newbie: correct technique to resume socket reseiving

  • Thread starter Thread starter Namor
  • Start date Start date
N

Namor

Hi there!

I use microsoft's asyncronous socket server sample.
This sample can receive many messages from client but, after it sends
something to client, it stop receiving. I don't know why. There is no
socket.Shutdown() or socket.Close().

So, added this code to SendCallback() function after EndSend():

Dim state As New StateObject()
state.workSocket = handler
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, _
0, New AsyncCallback(AddressOf ReadCallback), state)

So that after socket sent the message, new StateObject created and
socket begins receiving again.

Is that good idea? Can new and new and new StateObjects cause mamory
leak problems or something? Or there is another way to force socket to
receive again after sending?

Thanks!
Roman
 
Back
Top