System.Net.Sockets

  • Thread starter Thread starter Lee Atkinson
  • Start date Start date
L

Lee Atkinson

I am using a socket to listen to TCP data being sent from a third
party application. I create the socket using:

new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);

and use BeginAccept and BeginReceive to read data asynchronously. All
works well, unless I close my app and restart it, without stopping the
sender app.

I suspect it's due to TCP being connection-based, and my app not
receiving any new requests to accept connections again from the sender
app.

Is there anyway I can get around this so that I can receive data even
if the my app starts after the sender? Or can this only be 'fixed' by
the sender reconnecting?

Many thanks.

Lee
 
Lee Atkinson said:
I am using a socket to listen to TCP data being sent from a third
party application. I create the socket using:

new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);

and use BeginAccept and BeginReceive to read data asynchronously. All
works well, unless I close my app and restart it, without stopping the
sender app.

And then what happens?
I suspect it's due to TCP being connection-based, and my app not
receiving any new requests to accept connections again from the sender
app.

That would certainly mean the new instance didn't hear anything.
Is there anyway I can get around this so that I can receive data even
if the my app starts after the sender? Or can this only be 'fixed' by
the sender reconnecting?

No, the sender should reconnect. You could use broadcast UDP, but then
you'd be in pretty unreliable territory.
 
Back
Top