
Reconnection issue between Winsock Server(VB6) and TCP Client (VB.NET)
I have a program (Winsock Server) written with VB6 which is connected
by a TCP Client (written in VB.NET).
The developer who writes the TCP Client told me that the TCP Client
can't reconnect to my Program (Winsock Server) after TCP Client
crashes or restarts. It can only reconnect to my program after my
program's restarted.
I did the same testing with a simple Winsock Client i wrote and
everything works fine.
What i notice is that when TCP Client tries to reconnect, Winsock
ConnectionRequest event is not being fired anymore.
Having no working knowledge about VB.NET, please advise the workaround
of this issue.
Below is my Winsock Server code (I removed other part of the program
which is unrelated to this issue).
Private Sub Form_Load()
On Error GoTo fixerr
' Set the LocalPort property to an integer.
' Then invoke the Listen method.
tcpServer.LocalPort = 500
tcpServer.Listen
Text1.Text = Text1.Text & " Listening via port " & tcpServer.LocalPort
& " at " & Now & vbCr
fixerr:
If Err.Number <> 0 Then
Text1.Text = Text1.Text & "error " & Err.Number & " " &
Err.Description & vbCr
End If
End Sub
Private Sub tcpServer_Close()
On Error GoTo fixerr
tcpServer.Close
Text1.Text = Text1.Text & " Client Disconnected via port " &
tcpServer.LocalPort & " at " & Now & vbCr
tcpServer.LocalPort = 500
tcpServer.Listen
Text1.Text = Text1.Text & " Listening via port " & tcpServer.LocalPort
& " at " & Now & vbCr
fixerr:
If Err.Number <> 0 Then
Text1.Text = Text1.Text & "error " & Err.Number & " " &
Err.Description & vbCr
End If
End Sub
Private Sub tcpServer_ConnectionRequest _
(ByVal requestID As Long)
On Error GoTo fixerr
' Check if the control's State is closed. If not,
' close the connection before accepting the new
' connection.
Text1.Text = Text1.Text & " Client attempts to connect via port " &
tcpServer.LocalPort & " at " & Now & vbCr
If tcpServer.State <> sckClosed Then
tcpServer.Close
End If
' Accept the request with the requestID
' parameter.
tcpServer.Accept requestID
If tcpServer.State = sckConnected Then
Text1.Text = Text1.Text & " Connected by client via port " &
tcpServer.LocalPort & " at " & Now & vbCr
End If
fixerr:
If Err.Number <> 0 Then
Text1.Text = Text1.Text & "error " & Err.Number & " " &
Err.Description & vbCr
End If
End Sub
Private Sub tcpServer_DataArrival _
(ByVal bytesTotal As Long)
On Error GoTo fixerr
' Declare a variable for the incoming data.
' Invoke the GetData method and set the Text
' property of a TextBox named txtOutput to
' the data.
Dim strData As String
tcpServer.GetData strData
txtOutput.Text = strData
fixerr:
If Err.Number <> 0 Then
Text1.Text = Text1.Text & "error " & Err.Number & " " &
Err.Description & vbCr
End If
End Sub