发布网友 发布时间:2023-01-06 10:47
共1个回答
热心网友 时间:2023-10-18 03:42
我只能给你主要代码。你如果看得懂你能实现了。。因为涉及部分算法。所以只能给你主要代码。也是你想要的。多客服端连接。好代码如下 客服端没什么东西可讲。就是连接。服务端可以同时有多个客服端连接。 '服务端代码如下。主要部件winsock. 一个名称为wslisten用来监听,再建一个winsock1() index为0.控件数组 如果哪里不懂。QQ45656837. Private Gac() As Boolean Dim Socknumber As Integer Private Sub Form_Load() wslisten.LocalPort = 2008 wslisten.Listen Socknumber = 0 End Sub Private Sub Form_Unload(Cancel As Integer) Winsock1(0).Close End Sub Private Sub Winsock1_Close(Index As Integer) Winsock1(Index).Close Unload Winsock1(Index) Gac(Index) = False Text3.Text = Int(Text3.Text) - 1 End Sub Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long) Dim c As String Winsock1(Index).GetData c, vbString Dim i As Integer For i = 1 To UBound(Gac) If Not i = Index Then If Gac(i) Then Winsock1(i).SendData c DoEvents End If End If Next i End Sub Private Sub wslisten_ConnectionRequest(ByVal requestID As Long) Socknumber = Socknumber + 1 Load Winsock1(Socknumber) Winsock1(Socknumber).Accept requestID ReDim Preserve Gac(Socknumber) Gac(Socknumber) = True Text3.Text = Int(Text3.Text) + 1 End Sub 参考资料: http://www.3estudio.cn/blog 希望能帮到你。。祝你成功!