how to check whether port is open at client's pc?

I've got UDPserver which recieves messages from clients and sends response to them. But I need to check if UDPclients is online or not. With isReachable I can test whether pc online or not. But when differents clients use same pc but with differents ports how to check whether port is open or not(Client1 with port 5678 is online but client2 6777 is off.IP 192.168.1.7 IP isReachable in this case but client2 is not)?

Upvotes: 1

Views: 471

Answers (4)

Paaske
Paaske

Reputation: 4403

If the only issue is to know if a client is alive, then keep-alive message from the client is easiest. You can identify the client for example from the content of the package (or the sender port).

If you wish to send messages to the clients, I think you'll have to have a UDP server on both ends, and then exchange the ports the 'client-servers' are listening on and use that for communications.

Of course, the latter will cause issues with firewalls as most will block all incoming traffic.

Upvotes: 1

Grims
Grims

Reputation: 807

IsReachable will only do a ICMP echo request (ping) on the given host so event if your client is not running but as long as your host responds to ICM requests it will show as reachable.

If you which to check if your remote client is running, you will need to implements a simple "ping" protocol : ie: your server will send a special message to the client and the client has to respond to it.

Upvotes: 1

Eight-Bit Guru
Eight-Bit Guru

Reputation: 9971

You're conflating two different concepts here. The 'isReachable' function is an IP-layer property which is simply checking to see if the IP address in question is responding to IP-protocol packets (which it is).

UDP is a broadcast datagram protocol designed for unacknowledged data broadcasts over IP, so it has no inbuilt concept of 'reachability'. Your UDP client must somehow watch for incoming detection messages, and respond to them accordingly.

Upvotes: 1

Nick
Nick

Reputation: 25799

UDP is a connectionless, unreliable packet-oriented protocol. If there is no socket bound to a particular port on the remote machine then the packet will simply be dropped.

You would have to implement some sort of protocol which supported detection of whether a client is online or not. Perhaps sending a keep-alive type message periodically.

Upvotes: 1

Related Questions