Expert Input for Asynchronous Socket

  • Thread starter Thread starter Chan
  • Start date Start date
C

Chan

Building an Asyc Socket DLL using C#, I followed MS .NET FRAMEWORK
library sample (see "Asynchronous Client Socket Example") and created
a DLL called MSSock. I then reference MSSock in a .exe c# program to
test it.

This .exe has a form which has a button and a text field to invoke the
DLL async communication and display return data.

<F5>, runs ok and data returned is being displayed. Without exiting
the app, click on the button again, this supposed do exactly connect,
send, receive, close and displaying data. But, the following comes up
in a dialog box,

----------------------------------------------------------------------------
An unhandled exception of type 'System.Net.Sockets.SocketException'
occurred in netsock.dll

Additional information: A request to send or receive data was
disallowed because the socket is not connected and (when sending on a
datagram socket using a sendto call) no address was supplied
----------------------------------------------------------------------------

Ok, I set a breakpoint at the line the DLL is called, stepping through
all of the lines, it ran perfectly fine, no error, returns data as
expected.

It's repeated many times with machine rebooting. I opened up a DOS
window, use

netstat -p TCP

to check socket connection statistics, whenever I got the above error,
netstat showed the State as ESTABLISHED.
 
Most likely your overwriting the IPAddress in an overlapped previous
callback before the current SentTo can send or something like that. Would
probably need to post the code or a small but complete sample of the code
that shows the problem.
 
Back
Top