:(Hi, I have an error that keeps coming up when I try to run a simple chat program from the Mastering Visual Basic series. this is the error I get: Run-time error 10054, the connection is reset by remote side. Here is the code that the debugger sends me to:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s As String
If bytesTotal > 0 Then
' Data has arrived. Add it to the label control. Maintain
' only the last 2KB of text in the label control.
Winsock1.GetData s, vbString
lblReceivedData = s & vbCrLf & Left$(lblReceivedData, 2048)
End If
End Sub
The complete program:
Option Explicit
Private Sub cmdBind_Click()
' Set the communication properties
Winsock1.RemoteHost = txtPeerMachine
Winsock1.RemotePort = txtPeerPort
Winsock1.Bind txtLocalPort
End Sub
Private Sub cmdSend_Click()
' Send the data to the peer machine
Winsock1.SendData txtSendData
txtSendData = ""
End Sub
Private Sub txtLocalPort_Change()
EnableBinding
End Sub
Private Sub txtPeerMachine_Change()
EnableBinding
End Sub
Private Sub txtPeerPort_Change()
EnableBinding
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s As String
If bytesTotal > 0 Then
' Data has arrived. Add it to the label control. Maintain
' only the last 2KB of text in the label control.
Winsock1.GetData s, vbString
lblReceivedData = s & vbCrLf & Left$(lblReceivedData, 2048)
End If
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 "A Winsock Error has occurred. " & vbCrLf & _
"Error No. " & Number & " " & Description
End Sub
Private Sub EnableBinding()
' Enable the Bind button only if the peer machine,
' peer port, and local port have been specified.
cmdBind.Enabled = Len(txtPeerMachine) > 0 And _
Len(txtPeerPort) > 0 And Len(txtLocalPort) > 0
End Sub
The interface is a single from with text boxes for remote host, remote port, local port and send data. Data is received in label. It has a bind and send buttons.
Thanks for any suggestions,
Stuart