Hi,
I need a client to send the host
computer its IP address. and client
doesnt know the hosts IP and the hosts
doesnt know the clients..
How do I do that?
Printable View
Hi,
I need a client to send the host
computer its IP address. and client
doesnt know the hosts IP and the hosts
doesnt know the clients..
How do I do that?
Is it possable to send a server your
IP and the client gets it and connects
to the IP specified?
I'm not very sure about this, as I'm new to internet programming myself. But this may help a little bit.
In the client code put in this.
in the host code put in this...Code:Private Sub Command1_Click()
On Error GoTo ****
Winsock1.Connect "127.0.0.1 , 80" '127.0.0.1 being the ip of the host machine and 80 being the port to connect to.
****:
MsgBox "error"
End Sub
Private Sub Winsock1_Connect()
Dim i As String
On Error GoTo err
i = Winsock1.LocalIP
Winsock1.SendData i 'sends the ip of the machine your on
End If
Winsock1.Close
err:
MsgBox "Destination unreachable"
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If (Winsock1.State <> sckClosed) Then Winsock1.Close ' If not closed then call close method to cleanup socket status
Winsock1.LocalPort = 0 ' Clear the localport
Winsock1.Accept requestID ' Accept the incoming connection
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim INCOMING ' Sets the varible
Winsock1.GetData INCOMING, vbString ' Puts the incoming data into the varible
txtIP.Text = INCOMING
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Error: " & Description ' Descibes the error in the status box
End Sub
Remember I did not test this code as I was writing it, but I'm fairly sure it should work. If not you should be able to figure it out by looking through it.Code:Private Sub Winsock1_Connect()
On Error GoTo err
'You put whatever code you want here.
err:
MsgBox "Destination unreachable"
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If (Winsock1.State <> sckClosed) Then Winsock1.Close ' If not closed then call close method to cleanup socket status
Winsock1.LocalPort = 0 ' Clear the localport
Winsock1.Accept requestID ' Accept the incoming connection
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim INCOMING ' Sets the varible
Winsock1.GetData INCOMING, vbString ' Puts the incoming data into the varible
txtIP.Text = INCOMING
Winsock1.Close
If (Winsock1.State <> sckClosed) Then Winsock1.Connect txtIp.Text
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Error: " & Description ' Descibes the error in the status box
End Sub