Prøv denne kode det skulle nok kunne løse dit problem tror jeg
Du kan også downloade hele applikationen her
http://www.planet-source-code.com/upload/ftp/CODE_UPLOAD43503282000.zipOption Explicit
Private Sub cmdConnect_Click()
lblStatus.Caption = \"Connection to: \" & txtRemoteIP.Text & \":\" & txtRemotePort.Text \' Sets the status
Winsock1.Connect txtRemoteIP.Text, Val(txtRemotePort.Text) \' Connects the client to ip, val(port)
End Sub
Private Sub cmdDisconnect_Click()
Winsock1.Close \' Closes the connection
cmdConnect.Enabled = True \' Changes the buttons status
cmdDisconnect.Enabled = False
cmdListen.Enabled = True
cmdSend.Enabled = False
lblStatus.Caption = \"Disconnected\" \' Set the new status message
End Sub
Private Sub cmdExit_Click()
Winsock1.Close \' Closes the connection
End \' Exits
End Sub
Private Sub cmdListen_Click()
Winsock1.LocalPort = Val(txtLocalPort.Text) \' Sets the port to listen on
Winsock1.Listen \' Opens port
lblStatus.Caption = \"Listening on port: \" & txtLocalPort.Text \' Updates status
cmdConnect.Enabled = False \' Changes the buttons status
cmdDisconnect.Enabled = True
cmdListen.Enabled = False
cmdSend.Enabled = False
End Sub
Private Sub cmdSend_Click()
Winsock1.SendData txtOut.Text \' Sends the data to the other end
End Sub
Private Sub Form_Load()
cmdDisconnect.Enabled = False \' Sets the buttons
cmdSend.Enabled = False
End Sub
Private Sub txtIn_Change()
txtIn.SelStart = Len(txtIn.Text) \' Makes it so it scrolls down when more text is added
End Sub
Private Sub Winsock1_Connect()
lblStatus.Caption = \"Connected: \" & txtRemoteIP.Text & \":\" & txtRemotePort.Text \' Sets status
cmdConnect.Enabled = False \' Updates buttons
cmdDisconnect.Enabled = True
cmdListen.Enabled = False
cmdSend.Enabled = True
End Sub
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
txtRemoteIP.Text = Winsock1.RemoteHostIP \' Tells you their ip
txtRemotePort.Text = Winsock1.RemotePort \' Tells you their port
lblStatus.Caption = \"Connected: \" & txtRemoteIP.Text & \":\" & txtRemotePort.Text \' Updates status
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
txtIn.Text = txtIn.Text & INCOMING \' Adds the varible to the text box
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)
lblStatus.Caption = \"Error: \" & Description \' Descibes the error in the status box
End Sub