我做了一个多机通信程序,在程序中客户端需要给服务器发送数组.以下代码是客户端发送数组的源码,现在问题是这段代码在一台电脑上(即又是服务器又是客户端)没有问题,比如说要发送1,2,3,4.则接收也为1,2,3,4.但是如果是用两台电脑相连则不行,客户端发送以后没反应,但是如果在客户端连着发数据,服务可以接收,但是出错,比如发送1,2,3,4.刚接收为1,234
以下是客户端发送代码
Private Sub Command1_Click()
If Winsock1.State = 0 Then
Text5.Text = "请先连接再发送数据"
Exit Sub
End If
For i = 0 To 10
a(i) = Text1(i).Text
Winsock1.SendData a(i)
DoEvents
Next i
If js = 1 Then
MSHFlexGrid1.Row = 1
MSHFlexGrid1.Col = 0
MSHFlexGrid1.Text = "第1次发送"
For n = 1 To 11
MSHFlexGrid1.TextMatrix(js, n) = a(n - 1)
Next n
Else
MSHFlexGrid1.AddItem "第" & js & "次发送"
For n = 1 To 11
MSHFlexGrid1.TextMatrix(js, n) = a(n - 1)
Next n
End If
js = js + 1
Text5.Text = "发送成功"
End Sub
以下是服务器接收数据的代码
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim str As String
Winsock1(Index).GetData str, vbString
a(p) = str
p = p + 1
If p = 11 Then
MSHFlexGrid1.AddItem "第" & js & "次接收"
For n = 1 To 11
MSHFlexGrid1.TextMatrix(js, n) = a(n - 1) '为第N行中增加数据
Next n
js = js + 1
p = 0 'P归0
End If
End Sub
[此贴子已经被作者于2006-11-24 17:51:06编辑过]