Client server (service) application connecting locally but not over the network - c#

I have created a windows service server program in c# which will receive data messages from a serial port and then send those messages to any clients that have connected to the server. I have also developed the client program (windows form) in c#.
Originally the server program was developed as a console application to make development easier. While running the server as a console application the connections to the clients worked well, I could run a client on the same PC as the server and also connect a client on a laptop connected to the same network.
The connection method is:
-client starts up
-client broadcasts (udp) to a specific port
-server responds to the UDP broadcast
-client initiates a TCP connection with the server using the IP address obtained from the UDP response
Since changing the server from a console application to a windows service I can no longer connect the client program running on the laptop to the server using this method. The client program running on the same machine as the server connects successfully. Can anyone offer some advice on what to investigate?

To solve the issue I was having I added a new rule in the firewall settings of the machine running the server service application. I allowed the port used on incoming connections and this solved the problem for me.
I also changed the network discovery procedure:
Server broadcasts every second to a port (UDP)
Client awaits the broadcast packet from the server
Client establishes a TCP connection with the server using the IP address obtained from the broadcast packet

Related

Azure VPS as TCP server

I'm using an Azure VPS to host a TCP server (raw sockets) but the external client is timing out when it tries to connect to the server. I've already opened the TCP ports on Azure Portal.
It works locally so it can't be a problem on the code.
(Note that the address shown in the server print is just the local address, the client is pointing to the server external address)
Server running:
Client timeout:
Well it turns out the problem was the VM firewall. Just added the inbound rule and it worked!

How to build TCP connection between two different computers in local network in C#?

I am trying to use C# to develop a client running on a computer and a server running on another computer in local network. I want to let the client connect to the server using TCP socket. When I run client and server on one computer they can be connected but the connection cannot be built when client and server on different server. I guess the problem is the IP address. When I run them on one computer I use localhost as the IP address of both of them. So how can I deal with this problem when they are running on different computers in local network?

peer to peer chat with out the server

I am trying to make a peer to peer chat program. the scenario is much more complicated but I will simplify it to get help in the the part where its needed.
as a summary:
A- The Server
There is a server waiting for clients to connect, when a client connects it will be kept as waiting till the next client connects.
When the 2nd client connects to the server the server will return to each client the ip and the port of the other client, so both client can talk to each other without intervention of the server.
Then the server back to 1
B- The client
the client start a tcpClient connection with server.
wait the server response.
client receive a custom object that contain the ip and the port of
the other client
start chatting with the other client using the ip:port provided by
the server of the other client.
The question is: is this possible considering network and firewall security configuration (default) on the client machine?
The client might be behind pating or nating router.
The application is going to run on the internet or local network.
Note: the thing i need help is it possible in C# to implemented the client part of the application to act as server and listen to a port and receive connections knowing that the port is not configured on the possible front end router;
Are there alternative solutions? The main idea is to keep the server out of the picture after server step 2

I can't get TcpClient to connect to a TcpListener on another host

I have a simple client and server application that talk to each other over TCP/IP using TcpClient and TcpListener. If I run both the server and the client on the same computer with an IP address of 192.168.10.150, they can talk to each other just fine. However, if I move the client to a different computer on my home network, it can’t connect to the server any more (which is still running on 192.168.10.150). From the client computer, I can ping 192.168.10.150. I have turned off Windows Firewall on both computers. I am using port 2244, which I don’t think is used by something else. The two computers are both connected to the same wireless router. But this line of code in the client:
TcpClient client = new TcpClient("192.168.10.150", 2244);
Throws the following exception:
A connection attempt failed because the connected party did not
properly respond after a period of time, or established connection
failed because connected host has failed to respond
192.168.10.150:2244
Both computers are running XP. Any ideas how I get these to connect?
Thanks for the responses. It seems that a couple of you are correct that the network traffic was being stopped by the router. I hooked up the two computers with a switch, and they were able to talk. Unfortunately I haven't been able to successfully configure the router to allow the traffic, but that's OK, as I can just use the switch for now.

Windows phone: cannot connect to a computer using socket

Situation: there are two programs - client and server.
Server is working on my computer, client program is working on windows phone.
Server is listening for incoming connections ant receive data. Windows phone creates a socket(tcp connection) and sends data.
If I connect win-phone to my computer using USB cable, all works: connection establishes and data is transferring.
But when I create an "infrastructure-network" using the program "connectify", or connect to real wi-fi router (computer and win-phone both are connected to the same network) it is not working. I disabled windows firewall, but it is still not working.
How can it be explained? Where is the problem?
The problem was in ip address string in python server code.
I used "127.0.0.1" instead of "localhost" :(

Categories

Resources