views:

1191

answers:

1

Hi,

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?

+1  A: 

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.

Jon B
Interesting that a test code compiled/running under Mono, it does start listening on 0.0.0.0 if the IPAddress.Any is passed to the constructor.
Andrew Y