problem in client/server application  
Author Message
bola shokry





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

Hi every one,

I developed a client/server application .

client connect to server correctly if both are under the same router (in the same Lan) , but the problem arised when the client and the server arenot in the same Lan they cant connect together.

I checked the router configration ,it was correctly setup.

please if you have expirense in this problem help me.

Thanks for reading my message------------



.NET Development25  
 
 
Indian Ocean





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

Please post your code and exception stack trace you are getting in this case,



 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

You need to properly configure your Router to Forward the Port to correct computer. See your Router's Manual for more information on Port Forwarding...

I hope you'll get it done.

Best Regards,

Rizwan aka RizwanSharp



 
 
bola shokry





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

I think , you dont read my message carefully

I said : I configured my router and the problem still exist.

any way thanks RizwanSharp.

if you have any other help please tell me

thanks again


 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

I think , you dont read my message carefully

I said : I configured my router and the problem still exist.

any way thanks RizwanSharp.

if you have any other help please tell me

thanks again

I surely did understand your answer and I was just asking you to double check it or try your application someother else, with some other router etc....

Best Regards,

Rizwan aka RizwanSharp



 
 
bola shokry





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

ok , the problem in more details:

The server program run on my PC and my PC is under a router. The client program run on another PC use a dial up connection.

The server program listen to port 5000 on my PC and the client connect to port 5000 of the router.

I configured the router to forward any connection come to it from port 5000 to my PC. but they still cant connect together.

the code in server side : listener=new TcpListener(5000);
listener.Start(); //listen to port 5000 on my PC.

the code in client side: client=new TcpClient(serverIP,5000); // where serverIP is the router IP.

the router configuration: public port start=5000 , public port end= 5000, private port=5000, port type=TCP, host IP address=10.0.0.3; //where 10.0.0.3 is my PC IP under the router;

and the problem still exist,

please I need anyone help............... thanks


 
 
Indian Ocean





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

Hi,

Here is your problem,

the code in server side : listener=new TcpListener(5000);

Whenever you start TcpListener passing ONLY a port then it will start listening on the "local-ip" that is why it may work in LAN but not when someone connect from outside of LAN. Also this method is obsolete in .Net 2.0 so use the following, I think, it must solve your problem,



IPAddress ip = IPAddress.Parse("YourServerIP/RouterIP");
listener = new TcpListener(ip, 5000);

HTH,



 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

May be you are using 2 Network Interfaces... and Request for conneciton is going to the other one because your server's code doesnot tell that from where to accept the connection and yes what is refered by indian ocean that this constructor is obsoleted.

I would recomend using:

TcpListener listener=new TcpListener(IPAddress.Any, 5000);

listener.Start();

Specifying IPAddress.Any tells to to take request from all network interfaces if you have more than 1 network connection at the same time.

Try this and post back your results.

I hope this will work.

Best Regards,

Rizwan aka RizwanSharp



 
 
bola shokry





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

I tried it , but still not working
 
 
Indian Ocean





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

Hi,

You must have used "RounterIP" as ip as i have suggested, right !

Give this a try, i think this will work for sure,



IPAddress ip = IPAddress.Parse("YourServerIP"); //Here its your local server IP (NOT ROUTER IP) which is set as hostip in router - i think its 10.0.0.3
listener = new TcpListener(ip, 5000);

 

HTH,



 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

Hi,

You must have used "RounterIP" as ip as i have suggested, right !

Give this a try, i think this will work for sure,



IPAddress ip = IPAddress.Parse("YourServerIP"); //Here its your local server IP (NOT ROUTER IP) which is set as hostip in router - i think its 10.0.0.3
listener = new TcpListener(ip, 5000);

HTH,

He could not use Router's IP even accidently becuase He was using TcpListener listener=new TcpListener(IPAddress.Any, 5000); as I suggested which listens on all local Network Intefaces attached to the local computer, It'll automatically cover your sugested way too.

Best Regards,

RIzwan aka RizwanSharp



 
 
bola shokry





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

HI everyone , thanks for your helping

I tried to use IPAddress.Pares("MyServerIP",portNumber) it caused an ArgumentException.

I tried to use also listener=new TcpListener(IPAddress.Any,portNumber) but i didn't observe any chage!!

The strange is that : I tried to run the program with alot of people in another countries and it always not work except one time it worked (I dont know why !!!!!!!) although I didn't change any thing.

Note: I shutdown every firewall in server side and client side.

please please I need help again. Thanks


 
 
Indian Ocean





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

Hi,

RizwanSharp is right that if IPAddress.Any is used then it includes my solution too, I was not aware that you are using that solution so i put my doubt.

I saw that his post is marked as Answer so i thought you got solution from his post but wondering that you still have problem..

Any way, you said that using IPAddress.Parse gave you the ArgumentException, i dont understand that also, you wrote that you used IPAddress.Parse("IP", port); but there is no such method. Its IPAddress.Parse("ip address");

Let me tell you what i did on my server (we have same situation like you, our server is behind router and almost configured the same way what you did).

We have router which opened let's say 12345 port on ip 192.168.0.107

My server machine has configured for "Obtain an IP Automatically" and it has ip 192.168.0.107

On command prompt, "ipconfig /all" gives,
 Dhcp Enabled. . . . . . . . . . . : Yes
 Autoconfiguration Enabled . . . . : Yes
 IP Address. . . . . . . . . . . . : 192.168.0.107
 Subnet Mask . . . . . . . . . . . : 255.255.255.0
 Default Gateway . . . . . . . . . : 192.168.0.1
 DHCP Server . . . . . . . . . . . : 192.168.0.1
 DNS Servers . . . . . . . . . . . : 192.168.0.1

And router ip is lets say 66.66.66.6 so now my clients are requesting to connect to 66.66.66.6 and router forwarding that request to machine with ip 192.168.0.107

This works perfectly in inter-country situation too.

I am not sure, if your ip 10.0.0.3 causes any problem or not but it seems that it is networking problem rather than the application problem.

So if you find something wrong in your any of configuration then correct it, probably it will work.

HTH,



 
 
bola shokry





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

I am really confused.

The application work with people and dont work with others.Note that my computer is the server in all cases.

what is it means


 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, problem in client/server application Top

I am really confused.

The application work with people and dont work with others.Note that my computer is the server in all cases.

what is it means

Your application should surely work if assured that Router is Well configured.

I would recommend you Give your application a try on some other Environment with same type of flow i.e Client -> Router -> Server. May be with Some Friends's Router .

Lets See what's wrong

Best Regards,

Rizwan aka RizwanSharp