By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,515 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,515 IT Pros & Developers. It's quick & easy.

how to get sockets accepting port

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
as a server listened u have to write ur owned port number b4 u sending
out ur port number to client.
i give u site to make u understanding.
http://www.developerfusion.com/show/3997/4/
regsrds

Mitch Mooney wrote:
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


Nov 21 '05 #2

P: n/a
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.

"Supra" <su*****@rogers.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
as a server listened u have to write ur owned port number b4 u sending
out ur port number to client.
i give u site to make u understanding.
http://www.developerfusion.com/show/3997/4/
regsrds

Mitch Mooney wrote:
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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.