Issue #1 [Sending Message from server to client]
Public Sub SendMessage(ByVal msg As String, ByVal MsgClient As TcpClient) Dim sw As IO.StreamWriter Try SyncLock MsgClient.GetStream sw = New IO.StreamWriter(MsgClient.GetStream) sw.Write(msg) sw.Flush() End SyncLock Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub
When the above function is executed the message is not delivered to the client, this function does work when the listener has a new incoming client and I need to process data to be sent back to the client. I made a property to store the TcpClient protocol but that hasn't worked, the property is Client.ClientSocket.
#Concluding Issue 1
Issue 2 [Properly disposing a specific client]
Private AClients As New List(Of ConnectedClient) Private ConClient As ConnectedClient Public Sub SrvKickClient(ByVal ID As Integer) For Each Client As ConnectedClient In AClients If Client.ClientId = ID Then ConClient.SendMessage("You have been kicked by the server.", Client.ClientSocket) ConClient.CDisCon(Client.ClientSocket) AClients.Remove(Client) ServerMsg("Client " & Client.Username & " has been kicked.") Exit For End If Next End Sub
So this is my function for disposing a specific client, now it does work but when we have our problem from issue 1. The ConClient.SendMessage doesn't send a message to the client before removing them. Honestly this is like a big loop everything leads back to the SendMessage function which only works for incomming clients. There are no errors nothing. Just an empty richtextbox. If anyone has an idea of what could be wrong please feel free to post below with a solution or suggestion. Thank you all, and kudos everyone.