我想写一个聊天的小工具,但现在只能在本机实现,如何达到远程会话呢,高手指点下...
目前的代码如下 :
===============================服务端============================
Private Sub cmdexit_Click() '退出
server.Close
Unload Me
End Sub
Private Sub Form_Load()
server.LocalPort = 2000 '设置端口
server.Listen '开始侦听
txtreceive.Locked = True '禁止输入
End Sub
Private Sub server_ConnectionRequest(ByVal requestID As Long) '建立连接
'如果server控件的状态目前不是处于关闭的状态时,在允许远程设备连接时,必须要关闭目前的控制的运行
If server.State <> sckClosed Then server.Close
server.Accept requestID '表示客户请求连接的ID号
End Sub
' 当客户向服务器发送数据到达后 , 产生DataArrival事件, 在事件中接收数据, 利用GetData方法接收数据
Private Sub server_DataArrival(ByVal bytesTotal As Long) '接收消息
Dim ClientNews As String '用于接收客户端的消息
server.GetData ClientNews '接收
If txtreceive.Text = "" Then '判断txtreceive是否存在内容
txtreceive.Text = "客户端:" & ClientNews
Else
txtreceive.Text = txtreceive.Text & vbCrLf & "客户端:" & ClientNews '换行显示
End If
End Sub
Private Sub cmdsend_Click() '发送数据
server.SendData txtcontent '将内容发送出去
End Sub
Private Sub server_SendComplete() '发送完毕并显示已发送的数据
If txtreceive.Text = "" Then '判断txtreceive是否存在内容
txtreceive.Text = "服务端:" & txtcontent.Text
Else
txtreceive.Text = txtreceive.Text & vbCrLf & "服务端:" & txtcontent.Text '换行显示
End If
End Sub
============================客户端===============================
Private Sub cmdexit_Click() '退出
client.Close
Unload Me
End Sub
Private Sub cmdsend_Click() '发送数据
client.SendData txtcontent.Text
End Sub
Private Sub Form_Load()
client.RemoteHost = "127.0.0.1" '指定服务器主机
client.RemotePort = 2000 '指定服务器端口
client.Connect '连接到服务器
End Sub
' 当客户向服务器发送数据到达后 , 产生DataArrival事件, 在事件中接收数据, 利用GetData方法接收数据
Private Sub client_DataArrival(ByVal bytesTotal As Long) '接收消息
Dim ClientNews As String '用于接收客户端的消息
client.GetData ClientNews '接收
If txtreceive.Text = "" Then '判断txtreceive是否存在内容
txtreceive.Text = "服务端:" & ClientNews
Else
txtreceive.Text = txtreceive.Text & vbCrLf & "服务端:" & ClientNews '换行显示
End If
End Sub
Private Sub client_SendComplete() '发送完毕并显示已发送的数据
If txtreceive.Text = "" Then '判断txtreceive是否存在内容
txtreceive.Text = "客户端:" & txtcontent.Text
Else
txtreceive.Text = txtreceive.Text & vbCrLf & "客户端:" & txtcontent.Text '换行显示
End If
End Sub