Hi i am writing a socket client/server application in VB6. i have the following code
Private Sub sockMain_ConnectionRequest(ByVal requestID As Long)
If sockMain.State <> sckClosed Then
sockMain.Close
End If
sockMain.Accept requestID
Debug.Print "Accepted connection from: " & sockMain.RemoteHostIP & vbCrLf
End Sub
its printing the IP but the last digit is missing 开发者_高级运维example, if my connection is from "192.168.1.123" then it shows "192.168.1.12" only
I've tried the exact same code and it works on my machine. I tried using telnet from the same machine, and also from a laptop and the correct IP address was printed in both cases.
I have to agree with ckv and say that its the way you are printing RemoteHostIP
.
This is a known bug in KB957924 Microsoft Visual Basic 6.0 Service Pack 6 Cumulative Update (link) in both v1 and May 2009 v2. This is why some people can duplicate it and some can't. It also is limited to the second and subsequent usage of the control.
It is discussed here.
As a really ugly workaround you can call recvfrom
in the wsock32.dll
lib with the sockMain.SocketHandle
, a small buffer and the MSG_PEEK
parameter (&H2
) to retrieve the socket address directly. This must be done before calling sockMain.GetData()
. Then you have to parse out the IP address yourself. I can post code that does this for the specific case I'm using (UDP) if requested.
I'm not sure it will work in your case since it looks like you're using TCP and Accept.
精彩评论