我正在尝试测试一台服务器接受多个连接或多个客户端的场景。
目的是将数据转发到具有不同IP和不同端口的另一台服务器。每当我在另一台服务器上查看不同的连接时转发数据。
这是我的代码:
Private Sub ConectarTcp(ByVal id_gps As String, ByVal data As String)
Try
With WinSockClient
.IPDelHost = "192.168.5.8"
.PuertoDelHost = 3030
.Conectar()
End With
WinSockCliente.EnviarDatos(trama)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub Conectar()
Dim tcpClnt As TcpClient
Dim tcpThd As Thread
tcpClnt = New TcpClient()
tcpClnt.Connect(IPDelHost, PuertoDelHost)
Stm = tcpClnt.GetStream()
tcpThd = New Thread(AddressOf LeerSocket)
tcpThd.Start()
End Sub
Public Sub EnviarDatos(ByVal Datos As String)
Dim BufferDeEscritura() As Byte
BufferDeEscritura = Encoding.ASCII.GetBytes(Datos)
If Not (Stm Is Nothing) Then
'Envio los datos al Servidor
Stm.Write(BufferDeEscritura, 0, BufferDeEscritura.Length)
End If
End Sub