结构如下:一个服务端两个客户端,用两个客户端分别向服务端发送数据,服务端都能接收成功,可是用服务端向客户端发送数据时,不能发送成功。服务端源码如下:
Option Explicit
Private intMax As LongPrivate Sub Command1_Click()
'向下发送数据
Dim i As Integer
For i = 1 To intMax
If tcpServer(i).State <> sckClosed Then
tcpServer(i).SendData "测试" & Text1.Text & i
End If
Next i
End SubPrivate Sub Command2_Click()
client.Show
client2.Show
End SubPrivate Sub Form_Load()
intMax = 0
'进行侦听
tcpServer(0).Protocol = sckTCPProtocol
tcpServer(0).LocalPort = 1234
tcpServer(0).Listen
'打开客户端
client.Show
client2.Show
End Sub
Private Sub tcpserver_Close(index As Integer)
If tcpServer(0).State <> 0 Then tcpServer(0).Close
tcpServer(0).Protocol = sckTCPProtocol
tcpServer(0).LocalPort = 1234
tcpServer(0).Listen
End SubPrivate Sub tcpserver_ConnectionRequest(index As Integer, ByVal requestID As Long)
If index = 0 Then
intMax = intMax + 1
Load tcpServer(intMax)
tcpServer(intMax).LocalPort = 1234 + intMax
tcpServer(intMax).Accept requestID
End If
End SubPrivate Sub tcpserver_DataArrival(index As Integer, ByVal bytesTotal As Long)
Dim str As String
tcpServer(index).GetData str
Text1.Text = str
End Sub
Option Explicit
Private intMax As LongPrivate Sub Command1_Click()
'向下发送数据
Dim i As Integer
For i = 1 To intMax
If tcpServer(i).State <> sckClosed Then
tcpServer(i).SendData "测试" & Text1.Text & i
End If
Next i
End SubPrivate Sub Command2_Click()
client.Show
client2.Show
End SubPrivate Sub Form_Load()
intMax = 0
'进行侦听
tcpServer(0).Protocol = sckTCPProtocol
tcpServer(0).LocalPort = 1234
tcpServer(0).Listen
'打开客户端
client.Show
client2.Show
End Sub
Private Sub tcpserver_Close(index As Integer)
If tcpServer(0).State <> 0 Then tcpServer(0).Close
tcpServer(0).Protocol = sckTCPProtocol
tcpServer(0).LocalPort = 1234
tcpServer(0).Listen
End SubPrivate Sub tcpserver_ConnectionRequest(index As Integer, ByVal requestID As Long)
If index = 0 Then
intMax = intMax + 1
Load tcpServer(intMax)
tcpServer(intMax).LocalPort = 1234 + intMax
tcpServer(intMax).Accept requestID
End If
End SubPrivate Sub tcpserver_DataArrival(index As Integer, ByVal bytesTotal As Long)
Dim str As String
tcpServer(index).GetData str
Text1.Text = str
End Sub
解决方案 »
- 弹出式菜单求教高手相助,谢谢!!!
- vb中利用LISTVIEW控件显示SQLserver中的一个表的内容?
- 菜单问题
- 怎么用语句动太创建一个textbox数组?编辑事件该怎么编辑?
- 请教:所需要的数据已经从数据库取出,显示在界面上的控件中,请问如何按照规定的报表格式做打印预览和打印啊?
- 用VB的都是一些很菜的程序员的工具!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 新手问,关于函数定义,参数可不可以为数组?
- 请问用什么方法可以对报表的下一次显示进行刷新?
- 小问题,请问一个控件的位置(left,top)的单位和它的大小(width,height)的单位有什么关系?
- VB中调用AUTOCAD
- 如何调整DataGrid中行的宽度和高度?
- 紧急求助,VB编写的ActvieXdll库,不能重新编译(高手进来,分不够在加)
Private Sub Command1_Click()
'向下发送数据
Dim i As Integer
For i = 1 To intMax
If tcpServer(1).State <> sckClosed Then
tcpServer(1).SendData "测试" & Text1.Text & i
End If
Next i
End Sub可是为什么不能向客户端2发送数据?