how to get sockets accepting port

M

Mitch Mooney

Im trying to make a wrapper and need to return the local port that the new
connection/socket is being made on. The following code the RaiseEvent, the
tmpsoc.localPort is returned as 0. How do I get the localport the server is
going to be handling the new connection?

Private Sub acceptCallback(ByVal ar As IAsyncResult)

Try
Try
Dim tmpsoc As clsSocket = New clsSocket(socket.EndAccept(ar))
RaiseEvent onAccept(tmpsoc.localPort, tmpsoc)
Catch e As Exception
doError(Err.Number, Err.Description)
End Try

beginAccept()
Catch e As SocketException
doError(Err.Number, Err.Description)
Catch e As ObjectDisposedException
Close()
Catch e As Exception
doError(Err.Number, Err.Description)
End Try

End Sub
 
M

Mitch Mooney

Umm, yes I have called socket.Bind(New IPEndPoint(IPAdress.Any,port) ):
socket.Listen(5). I do make an connection with the client however the socket
that is returned by the socket.EndAccept(ar) method the localport property
is 0. It should not be 0, it should be the localport of the server machine
that the new connection is going to end up communicating on.
 

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