newbie: correct technique to resume socket reseiving

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
 

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