用VB编写一个即时通讯软件的具体过程和代码
展开全部
这是一个我找的简单的:
客户端程序的代码:
(运行在电脑A上)
Private
Sub
Command1_Click()
'发送按钮
tcpClient.SendData
Trim(Text1.Text)
End
Sub
Private
Sub
Command2_Click()
'退出按钮
tcpClient.Close
Unload
Me
End
Sub
Private
Sub
Form_Load()
tcpClient.Protocol
=
sckTCPProtocol
tcpClient.RemoteHost
=
"192.168.1.52
"
tcpClient.RemotePort
=
1001
tcpClient.Connect
End
Sub
服务器端程序的代码:(运行在电脑B上)
Private
Sub
Form_Load()
tcpServer.Protocol
=
sckTCPProtocol
tcpServer.LocalPort
=
1001
tcpServer.Listen
End
Sub
Private
Sub
tcpServer_ConnectionRequest(ByVal
requestID
As
Long)
If
tcpServer.State
<>
sckClosed
Then
tcpServer.Close
End
If
tcpServer.Accept
requestID
End
Sub
Private
Sub
tcpServer_DataArrival(ByVal
bytesTotal
As
Long)
Dim
strData
As
String
tcpServer.GetData
strData
Text1.Text
=
strData
End
Sub
客户端程序的代码:
(运行在电脑A上)
Private
Sub
Command1_Click()
'发送按钮
tcpClient.SendData
Trim(Text1.Text)
End
Sub
Private
Sub
Command2_Click()
'退出按钮
tcpClient.Close
Unload
Me
End
Sub
Private
Sub
Form_Load()
tcpClient.Protocol
=
sckTCPProtocol
tcpClient.RemoteHost
=
"192.168.1.52
"
tcpClient.RemotePort
=
1001
tcpClient.Connect
End
Sub
服务器端程序的代码:(运行在电脑B上)
Private
Sub
Form_Load()
tcpServer.Protocol
=
sckTCPProtocol
tcpServer.LocalPort
=
1001
tcpServer.Listen
End
Sub
Private
Sub
tcpServer_ConnectionRequest(ByVal
requestID
As
Long)
If
tcpServer.State
<>
sckClosed
Then
tcpServer.Close
End
If
tcpServer.Accept
requestID
End
Sub
Private
Sub
tcpServer_DataArrival(ByVal
bytesTotal
As
Long)
Dim
strData
As
String
tcpServer.GetData
strData
Text1.Text
=
strData
End
Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询