由于本人第一次编写数据包转发器,请高手看下对不对?
和服务器断开后,转发器自动连接的代码怎么写,放在哪里?重拨次数为3次转发器转发的数据是数据包,还要添加什么代码?
请高手知道下,急,谢谢
Private Sub Command1_Click()
Command1.Enabled = False
Command2.Enabled = True
If ipclient.Text = "" Then
ipclient.SetFocus
MsgBox "服务器IP不能为空"
ElseIf Text2.Text = "" Then
Text2.SetFocus
MsgBox "服务器端口不能为空"
Else
Winsockclient.Connect ipclient.Text, Text2.Text
End If
If Winsockclient.State = sckConnecting Then Label3.Caption = "与服务器正在连接"
If Winsockclient.State = sckClosed Then
Label3.Caption = "与服务器连接失败"
Command1.Enabled = True
Command2.Enabled = False
End If
End Sub
Private Sub Command2_Click()
Dim x As String
If Winsockclient.State = sckClosed Then
MsgBox "与服务器未连接"
ElseIf Winsockclient.State = sckConnected Then
Label3.Caption = "与服务器已断开"
Winsockclient.Close
Command1.Enabled = True
Command2.Enabled = False
End If
End Sub
Private Sub Form_Load()
'Winsockclient.RemotePort =1001
ipserver.Text = Winsockserver.LocalIP '本机IP地址
Winsockserver.LocalPort = 1002
Winsockserver.Listen
Text1.Text = Winsockserver.LocalPort
'中转站作为服务器时
Label3.Caption = "与服务器未连接"
Label6.Caption = "与客户端未连接"
Command1.Enabled = True
Command2.Enabled = False
End Sub
Private Sub textsend_Change()
Winsockserver.SendData textsend.Text
End Sub
Private Sub Winsockclient_Close()
Winsockclient.Close
MsgBox "与服务器断开连接"
Command1.Enabled = True
Command2.Enabled = False
Label3.Caption = "已断开"
End Sub
Private Sub Winsockclient_Connect()
Command1.Enabled = False
Command2.Enabled = True
Label3.Caption = "与服务器已连接"
End Sub
Private Sub Winsockclient_DataArrival(ByVal bytesTotal As Long)
Dim str As String
Dim at As String
Winsockclient.GetData str
Textget.Text = str
If Winsockserver.State = sckConnected Then
Winsockserver.SendData str
End If
End Sub
Private Sub Winsockserver_Close()
Winsockserver.Close
MsgBox "与客户端断开连接"
Winsockserver.LocalPort = Text1.Text
Winsockserver.Listen
End Sub
Private Sub Winsockserver_ConnectionRequest(ByVal requestID As Long)
If Winsockserver.State <> sckClosed Then Winsockserver.Close
Winsockserver.Accept requestID
Label6.Caption = "与客户端已连接"
End Sub