Private Sub Form_Load()
Form1.Show
Dim i As Integer
With Winsk(0)
.Protocol = sckTCPProtocol
.LocalPort = winsk_local_port
.Listen
End With
For i = 1 To max_sessions
Load Winsk(i)
Winsk(i).Protocol = sckTCPProtocol
Winsk(i).LocalPort = winsk_local_port
Next
End Sub
Private Sub Winsk_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim str As String
Dim i As Integer
If Index = 0 Then
For i = 0 To max_sessions
With Winsk(i)
If .State = sckClosed Then
.Accept requestID
Exit For
End If
End With
Next
End If
End Sub
Private Sub Winsk_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim str As String
Dim rc As Integer
Dim i As Integer
MsgBox "收到!"
Winsk(Index).GetData str, , bytesTotal
For i = 1 To max_sessions
With Winsk(i)
If .State = sckConnected Then
.SendData str
DoEvents
End If
End With
Next
End Sub
客户端ocx
Private Sub client_DataArrival(ByVal bytesTotal As Long)
Dim str As String
client.GetData str, , bytesTotal
MsgBox str
End Sub
Public Sub TestSocket()
If client.State = 0 Then
client.Connect
End If
If client.State <> 0 Then
MsgBox client.State
client.SendData "我是一只小鸭子~~"
Else
MsgBox "请先连接!"
End If
End Sub
Private Sub UserControl_Initialize()
client.RemoteHost = "127.0.0.1"
client.RemotePort = 8888
End Sub