obsolete TcpListener

G

Guest

OK, so I have a TcpListener that is waiting for sockets, this piece of code:

IPAddress localAddress = Dns.GetHostByName(Dns.GetHostName()).AddressList[0];
IPEndPoint localEP = new IPEndPoint(localAddress, 9000);
TcpListener tcpListen = new TcpListener(localEP);
tcpListen.Start();
Socket skt = tcpListen.AcceptSocket();
.... do some socket stuff
skt.Close();

does not accept sockets from a none .net client, infact instead of the
client: AYN
server: ACK/AYN
client: ACK

all you get is

client: SYN
server: ACK
with no SYN, which irritating as the socket is never registered as accepted,
so does not appear in the .Net code, but if I use an obsolete version of the
TcpListener constructor I get a valid connection, e.g

TcpListener tcpListen = new TcpListener(9000);
tcpListen.Start();
Socket skt = tcpListen.AcceptSocket();
.... do some socket stuff
skt.Close();

Why is it that the obsolete version seems to work, but the newer version
won’t? Am I missing something, or is .Net just being a bit strange?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Do you have more than one IP?

What you get if you use the constructor with an IP address & the port?

Cheers,
 
G

Guest

Hi,

I only have one IP address, using IP Address and port produces the same
results as the IPEndPoint.

Cheers for any help.
Rob
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Weird indeed.

Tell you what, post the code of the client and I will test both ends and
see what happen here

cheers,
 
W

William Stacey [MVP]

hmm. What is the IP address you are using or setting in the constructor.
The other constructor is listening an Any IPs (i.e. all). So one would
think it has something to do with the IP. It could be some funky
routing/config thing going on. You have RRAS, or VMWare installed? Check
all your IP devices again and disable anything you don't need or just for
testing.
 
T

TonyM

Rob White said:
OK, so I have a TcpListener that is waiting for sockets, this piece of
code:

IPAddress localAddress =
Dns.GetHostByName(Dns.GetHostName()).AddressList[0];
IPEndPoint localEP = new IPEndPoint(localAddress, 9000);
TcpListener tcpListen = new TcpListener(localEP);
tcpListen.Start();
Socket skt = tcpListen.AcceptSocket();
... do some socket stuff
skt.Close();

does not accept sockets from a none .net client,

Why is it that the obsolete version seems to work, but the newer version
won't? Am I missing something, or is .Net just being a bit strange?

This works for me when receiving a connection from a Windows CE platform
using Win32 on that end:

TcpListener remoteListen = new TcpListener(System.Net.IPAddress.Any,
300);
remoteListen.Start();

I only have 1 network card in that system as well, but went with the
IPAddress.Any, since there may be a chance that another system it's run on
in the future has another NIC.

Good Luck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top