Hi! Please, can anyone help me? I'm doing a test by creating a chat program that receives data from multiple clients. Everything is working well. My problem is that when two clients send messages at the same time, I just get the message from one of the clients. Is there a way to get incoming messages at the same time sorted by order of arrival?
below, part of the Server code.
Code:Public Sub LISTEN() Dim CLIENT As New NEWCLIENT While True Try CLIENT.SOCKETCLIENT = SERVER.AcceptSocket CLIENTIP = CLIENT.SOCKETCLIENT.RemoteEndPoint CLIENT.THREADCLIENT = New Thread(AddressOf READ) CLIENTS.Add(CLIENTIP, CLIENT) NEWCONEXION(CLIENTIP) CLIENT.THREADCLIENT.Start() Catch ex As Exception End Try End While End Sub Public Sub READ() Dim CLIENT As New NEWCLIENT Dim DATA() As Byte Dim IP As IPEndPoint = CLIENTIP CLIENT = CLIENTS(IP) While True If CLIENT.SOCKETCLIENT.Connected Then DATA = New Byte(1024) {} Try If CLIENT.SOCKETCLIENT.Receive(DATA, DATA.Length, 0) > 0 Then CLIENT.MSG = Encoding.UTF7.GetString(DATA) CLIENTS(IP) = CLIENT Datareceived(IP) Else Exit While End If Catch ex As Exception Exit While End Try End If End While Call ENDTHREAD(IP) End Sub Private Sub DATARECEIVED(ByVal IDTerminal As IPEndPoint) ListBox1.Items.Add(DATARECEIVED) End Sub




Reply With Quote
