Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TcpListener: Listen on every address, including GPRS IP address

We have a simple piece of legacy software with which we need to communicate using TCP/IP over port 15001. We need to listen on port 15001 for the legacy software to make a connection and then read whatever it sends us.

We have tested this solution accross the internet and it works just fine. If however we test the same solution across a GPRS TCP/IP network it does not.

All the basics have been checked, we can ping other devices in the GPRS network and port 15001 is not blocked by any firewall.

So maybe there is something wrong with my TcpListener?

It is initialized like this:

tcpServer = new TcpListener(IPAddress.Any, TCP_PORT);

I'm assuming it listens on every available IPv4 enabled interface on the system, because I used IPAddress.Any ?

Does anybody have any idea what the difference might be between the two networks? (Even though there shouldn't be any difference) and if there is something I need to change to my TcpListener?

like image 899
TimothyP Avatar asked Feb 03 '09 14:02

TimothyP


People also ask

How Tcp listener works?

A TCP listener provides TCP server socket support at a specific port within the node. The socket will accept connections and receive messages from a TCP client application. The TCP client application will send messages to the TCP listener in an XML format and ASCII delimited messages.

What is a TcpListener in c#?

The TcpListener class provides simple methods that listen for and accept incoming connection requests in blocking synchronous mode. You can use either a TcpClient or a Socket to connect with a TcpListener. Create a TcpListener using an IPEndPoint, a Local IP address and port number, or just a port number.


1 Answers

You need to specify the IP address on which you want to listen, instead of IPAddress.Any. See here. When you use IPAddress.Any, it will automatically choose the network interface for you. To listen on a certain interface (in your case, GPRS) you have to use the correct IP in the constructor.

This post has more information on getting the IP address for each nic.

Also, if you're looking to listen on every IP address at once, you'll need a TcpListener for each nic.

like image 91
Jon B Avatar answered Oct 15 '22 21:10

Jon B