Have anyone able to use visual studio socket server and client to work successfully over WAN network and not LAN?? I got it to work on LAN but not over the WAN.
By far the most common cause of problems when you go from LAN to WAN is firewall setup. If the server process is behind a NAT firewall, then you will need to connect to the public IP address assigned to you by your ISP, but it won't work until you set up a pinhole in the firewall's configuration that directs incoming connections to the appropriate internal IP/port.
Related
I have a synchronous TCP server and client application the works absolutely fine on two separate host machines.
What I'd like to know is what IP and port do I bind the server socket and the client socket to when the applications are both running on the same host machine.
I can't find any solid information on Google about this.
When I try and use my network IP which was 192.168.0.32 I get an error that says the Host actively refused the connection.
I cannot find any reasonable information about this error.
Can I listen and send on the same Port?
What IP address should I use to bind the server and the client, when both applications are running on the same machine?
Thanks for your time.
In order to run both client and server applications on the same host you should bind your server socket to localhost (you can actually write "localhost" it's a preserved word or 127.0.0.1 ) and address it from the client as well.
Localhost allways refers to the computer you work on.
If you'd like to access your server from a machine which is outer to your local network using your network ip you've mentioned, you should first search for "IP FORWARDING" option in your router settings and forward incomming requests to the machine where the server is running on.
Or (my favourite) use the great IP TUNNELING service of ngrok. You can find it here https://ngrok.com/
good luck.
So the answer to this question is that I must bind to my loop back address with separate ports for the client and the server !!
The IP address could be the loopback 127.0.0.1 for both, or your IP address, I don't see why it would not work.
The port on the other hand has to be the same for it to work, assuming the client application doesn't also listens to the port that you "bind" it to.
You have to tell the server on which port it should listen. The client then has to send data on the same port for the server to get the information.
This example should get you going: https://www.codeproject.com/Articles/1415/Introduction-to-TCP-client-server-in-C
The Tcp client/server code I'm working with is here: client and server.
As the title goes, I'm running the server code on my computer and I want to connect to it from another device using the client code. My question is, to what ip address does my client code have to connect? I know there are many related posts, but I'm only getting information on what's wrong rather than the solution.
This is a common problem when developing client/server applications. In a typical home network, there are multiple local IP addresses and a single external IP address. All devices communicating with your network from the outside must use the external IP address. However, when writing client/server applications, if you simply input the external IP address as the address to connect to, you'll quickly discover this won't work.
You need to use Port Forwarding. The client and server will be communicating over a specific port, and Port Forwarding is how your router knows which local IP address to send data to when the client is connecting to the external IP address. You want to login to your router settings, navigate to the section regarding Port Forwarding, and specify that communication over the port you're using in your server should be redirected to the local IP address that your server is running on. Exactly how to change these settings on your router depends on which router you're using.
Run the ipconfig command in a Windows Command Prompt on the machine running your server. Obtain the local IPv4 address from the results. This is the address to use when Port Forwarding the port used by your client/server applications. Adjust your router settings accordingly, and then your client should be able to use your external IP address just fine.
To find your external IP address, any website such as http://www.whatsmyip.org/ should work fine.
If you want to avoid all of these problems for now and simply test your application on your home network, then use the local IPv4 address found when running the ipconfig command on the machine your server is running on. Note that this will only work if both the client and server are running on the same network.
I have C# TCP Server program which is running into VMWare and network type is NAT. There TCP server works as a http server, so that I can connect it using browser. Now when I am connecting it using this url http://localhost:33333/OrderDetails, it works without any problem. But when I am trying to connect it from outside of VMWare using this link http://1.39.37.243:33333/OrderDetails (1.39.37.243 is my PC's public ip), then its not working. I can't change the network type NAT, because my customer's office Network system is also NAT system. Where am I doing it wrong ? Any thoughts or suggestion will be highly appreciated.
This isn't working because the machine receiving the TCP packets has no reason to forward them to the VM. In other words, this isn't working because you haven't done anything to make it work.
You need to configure VMWare's NAT to forward these incoming TCP connections to the VM.
You could also have other problems:
The server might not be listening on the right IP address. For example, if the listening socket is bound to localhost, only localhost connections will work.
There might be something else in the path keeping the TCP packets from getting to the host. For example, if the host itself is behind NAT, port forwarding may need to be configured in the router.
Port forwarding won't work from inside the LAN unless the router supports hairpinning. If the host itself is behind NAT, test from outside the LAN after setting up port forwarding in the router.
I can not connect to the TCP Server when i am on a different network
I am trying to connect to a Tcp server I created on another network, I have had no luck. Is there a way to do this?
What is is the IP Address that i need to put in to the Client program?
The server works fine if you are on the network but how do i connect is i am on a different network?
I have tried to connect with the external IP Address but the message just sat at the router, how do i make the router send the message to my PC?
What am i doing wrong
How do i fix it
Your TCP server should be on a system with a public(external) ip address. Clients then will be able to connect to the server even if they are inside a LAN. Note that the ip adresses in a LAN are different from external ip-addresses. The translation is called NAT.
So because your server runs on a computer inside a LAN it will not be accessible for other computers on the internet. Your router on the other hand has a public ip address which will be accessible from the internet. You can configure your router to forward a port to your computer so that your router connects your server with the internet. Note that port forwarding is often a bad security practice. Make sure that you pick a port number that's not used by any other program.
Also keep in mind that the TCP traffic from the client to the server is probably un-encrypted. This means that your traffic will be vulnerable for man-in-the-middle attacks. You should try to establish an connection which uses SSL. (Note: SSL is not equal to https) For more information please look at the OSI-model.
Hi,
I'm trying to connect my chat client to my server, but I keep getting an error. I have chat server which is running in a machine which is published in internet and it has fixed IP address and it is running on port 5001. When my chat client tries to connect to that server then I am get the error. The line which is raising error as follows
ipAddr = IPAddress.Parse(txtIp.Text);
// Start a new TCP connections to the chat server
tcpServer = new TcpClient();
tcpServer.Connect(ipAddr, 5001);
When I run both my chat client & server in my local machine with local machine IP, it works.
Please tell me what I need to changes in code as a result my chat server & client both can communicate over the internet. Thanks
Fixed IP might not be enough if it goes first through some network of computers.
You might need to Forward Port if it is simple network, or if it is more complicated probably it has own direct line but have closed Ports so you have to open them through Firewall within system as well within possible hardware that can filter traffic.
It probably not the code issue at all.
As well when you create server socket, try to Bind it to IPAddress.Any, because if you bind it to specific device it might be source of problem as well.