1
votes

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

2
If socket connection is established are you sure the connection is established from 192.168.1.123. Did you check what IP is shown as the remote IP in tcpview software.ckv
If the IP shows 192.168.1.123 then i dont there is any problem with the socket APIs. The problem will be with the way you are printing the IP.ckv
I am able see the active connection and able to transfer data, and in the debug mode if i check the connection state, the socket is in Connected state only. there is no issue with the connection. but the control RemoteHostIP is always shows the IP by truncating the last digit, is i connect client from local i am getting 127.0.0. instead of 127.0.0.1Dharma

2 Answers

0
votes

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.

0
votes

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.