Hezky vecer :] Rad bych poprosil o pomoc vyresit komunikaci pres tcp kde se pripojuje X klientu k jednomu servru. Obdoba kreslici tabule v jednom z clanku ale pro vic lidi.
Private Sub Server_Start(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
tcpListener = New Net.Sockets.TcpListener(System.Net.IPAddress.Any, 5678)
Try
tcpListener.Start(7)
Catch ex As Exception
Exit Sub
End Try
Sock = AddressOf SockConnect
tcpListener.BeginAcceptTcpClient(AddressOf SockConnect, Me)
MsgBox("start")
End Sub
Private Sub SockConnect(ByVal AR As IAsyncResult)
tcp = tcpListener.EndAcceptTcpClient(AR)
MsgBox("Client connected")
ns = tcp.GetStream()
ns.BeginRead(Buffer, 0, Buf_Size, AddressOf Read, Me)
tcpListener.BeginAcceptTcpClient(Sock, tcpListener)
End Sub
Private Sub Read(ByVal at As System.IAsyncResult)
Dim incoming As Integer = ns.EndRead(at)
If incoming < 1 Then Throw New Exception()
MsgBox(System.Text.Encoding.ASCII.GetString(Buffer, 0, incoming))
tcp.GetStream.BeginRead(Buffer, 0, Buf_Size, AddressOf Read, Me)
End Sub
V tomto kodu dojde ktomu, ze pri pripojeni a komunikaci druheho klinta, prerusi server komunikaci s prvnim :x Rad bych aby server mohl komunikovat s obema zaroven :x Predem diky za vase odpovedi :)
|