网络传输问题
我利用winsock控件编写了一个基于TCP协议的软件,只用来传递字符串。在XP下的局域网中测试没有问题,在Windows Server 2008服务器上确总是连不上。程序片段如下:Private Sub Winsock1_Close()
Winsock1.Close
Winsock1.Listen
Label1.Caption = "监听"
Label1.ForeColor = RGB(255, 0, 0)
Text1.Text = Text1.Text + Chr(13) + Chr(10) + Format(Date, "long date") & " " & Time & " " & "连接断开并进入监听状态"
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then
Winsock1.Close
Text1.Text = Text1.Text + Chr(13) + Chr(10) + Format(Date, "long date") & " " & Time & " " & "发出连接请求,端口暂时关闭"
Winsock1.Accept requestID
Text1.Text = Text1.Text + Chr(13) + Chr(10) + Format(Date, "long date") & " " & Time & " " & "接受发出的连接请求"
If Winsock1.State = sckConnected Then
Label1.Caption = "连接"
Label1.ForeColor = RGB(0, 128, 0)
Text1.Text = Text1.Text + Chr(13) + Chr(10) + Format(Date, "long date") & " " & Time & " " & "建立了新的连接"
Winsock1.SendData "接受"
End If
End If
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim myStr As String
Winsock1.GetData myStr
Text1.Text = Text1.Text + Chr(13) + Chr(10) + Format(Date, "long date") & " " & Time & " " & "接收到数据"
Text18.Text = myStr
If Winsock2.State = sckConnected Then
Winsock2.SendData myStr
Text1.Text = Text1.Text + Chr(13) + Chr(10) + Format(Date, "long date") & " " & Time & " " & "将数据转发"
End If
End Sub
请高手们解答,谢谢!