Asyncronous socket does not accept more then one connection

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
N

Nikolay Petrov

Code:
\\\\\\\\
Private Sub ConnectionsListener()
_acceptCallBack = New AsyncCallback(AddressOf acceptHandler)
'Dim listenSocket As Socket
Try
_listenSocket = New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
_listenSocket.Bind(New System.Net.IPEndPoint(IPAddress.Any,
Me._ApplicationPort))
_listenSocket.Listen(-1)
_listenSocket.BeginAccept(_acceptCallBack, _listenSocket)
Catch ex As Exception
msgbox(ex.tostring)
End Try
End Sub
////////


I run this as separate thread, but it only accepts first connection.

what is wrong?

tnx
 
_listenSocket.BeginAccept(_acceptCallBack, _listenSocket)

I run this as separate thread, but it only accepts first connection.

what is wrong?

You need to accept the connection on another socket handle. Use
_listenSocket to listen, then an array of connectionSockets to handle
the connection.
 
Back
Top