1

I have 2 sets of code for you to look at, both are available at PasteBin here:

First is my c# Socket server: http://pastebin.com/wvT4f19m

Second is my code within my AS3 application: http://pastebin.com/bKvabFSP

In the code, what I am trying to do is a simple Send/Receive to see what happens. If I open my application in 2 instances the c# socket server registers that they exist and all is fine!. If I close one of my instances, the c# server still thinks that the user exists and the socket isn't closed.

My code is based off the example at : http://msdn.microsoft.com/en-us/library/fx6588te.aspx

In the MS example, the following lines are added to the SendCallBack() function:

handler.Shutdown(SocketShutdown.Both);
handler.Close();

These definately close the sockets, something I do not want to happen.

I am new at socket programming and it has taken me a fair amount of time to play with the MS example to get it working roughly how I need it. The only problem is the acknowledgement of user disconnects so that I can remove the user from the Clients list that I have set up in the server. Also, when disconnects are acknowledged, I can inform other clients.

thanks all!

MWard
  • 135
  • 2
  • 6
  • 15
  • The socket server should never rely on the client to inform the the server it is disconnecting. With that being said I am not familiar enough with c# sockets to help you here but I can tell you in PHP it will trigger a change at which time I test read buffer and test the length if it is 0 length I count that as disconnected and clear out that client. The socket class you are using should trigger a change event of some sort when a client disconnects. I hope this helps you in some form. – The_asMan Sep 19 '11 at 17:58

2 Answers2

1

Upon each attempt to send data to the user, I do a quick check for a successful transmission/Poll the user and if it fails, the user is removed from my server.

MWard
  • 135
  • 2
  • 6
  • 15
0

Closing the socket won't affect your listener, it will only affect the current connection. Why do you say this is not what you want?

It sounds like this is exactly what you want.

TheCodeKing
  • 19,064
  • 3
  • 47
  • 70
  • When I close a client the server doesn't know the client is closed. Should I just attempt to send to a client and disconnect it if the data send fails? – MWard Sep 19 '11 at 14:13
  • 1
    Have a look at [this question](http://stackoverflow.com/questions/722240/instantly-detect-client-disconnection-from-server-socket), the suggestion is to poll the client. – TheCodeKing Sep 19 '11 at 17:24