Sockets Problem when converting winsock vb6 to c#

G

Guest

Hi. I have an application that uses sockets, as per below:

m_clientSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp );
int iPortNo =8000;
IPEndPoint ipEnd = new IPEndPoint (ip,iPortNo);
m_clientSocket.Connect ( ipEnd );

It works fine, however when I close my application, the application does not
receive any more data via the sockets and the application that sends it the
data (a windows service) must be restarted. I have a similar application that
uses the winsock control with vb6, and this works perfectly and the windows
service never needs to be restarted with the vb6 app, only the .net one.

I have tried different methods to close the socket when i shutdown my .net
app, such as :

m_clientSocket.Shutdown(System.Net.Sockets.SocketShutdown.Both);
m_clientSocket.EndReceive(s);
m_clientSocket.Close();
m_clientSocket = null;

But it makes no difference, the windows service always needs to be
restarted. Does anyone have any ideas at all?

Thank you!

Dave
 
C

chanmm

Ok Dave, you said "when I close my application" so I assume you have an
interface. Perhaps you can separate your interface with your windows
service. So you can start and stop them separately.

chanmm
 
G

Guest

i chanmm,

thanks for the post, i did a bit more tinkering.

I realised that when i ran my application from VS2003 i was not running the
socket shutdown code when i stopped the application. What a plum!

Cheers,
Dave
 

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