|
Answer» :(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, StuartThis may help
http://support.microsoft.com/kb/260018
Quote SYMPTOMS A run-time error occurs when you use network communications on a Windows 2000-based computer with a Winsock Control that uses User Datagram Protocol (UDP), and the Protocol PROPERTY of the control is set as sckUDPProtocol.
If a SendData request is sent to a RemoteHost that is not listening on the RemotePort, the DataArrival event fires and indicates that 1 byte of data is available. When you call the GetData method to retrieve that data, the following Microsoft Visual Basic run-time error occurs: '10054' - "The connection is reset by remote side". Normally, you can capture the error by using the Error event of the Winsock Control. However, even when the Error event is present for the control, the Error event never fires and a run-time error message box displays.
Code: [Select]RESOLUTION To work around this problem, use the Microsoft Visual Basic Standard Error Handling MECHANISM to catch the error. This workaround is illustrated in the following code snippet:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim szData As String
On Error Resume Next Winsock1.GetData szData If ERR Then ' handle the error here End if End Sub
:)Thanks for your help. I'll try that.
|