0 Replies - 610 Views - Last Post: 18 March 2012 - 03:13 PM Rate Topic: -----

#1 MrTwEaK   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 18-March 12

TCP Protocol SendMsg from server to client

Posted 18 March 2012 - 03:13 PM

Hello fellow coders, my name is Mr.TwEaK. I'm developing a TCP Client/Server application, I am having several issues so I'm going to acquaint them appropriately.

Issue #1 [Sending Message from server to client]
Public Sub SendMessage(ByVal msg As String, ByVal MsgClient As TcpClient)
        Dim sw As IO.StreamWriter
            SyncLock MsgClient.GetStream
                sw = New IO.StreamWriter(MsgClient.GetStream)
            End SyncLock
        Catch ex As Exception
        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)
                ServerMsg("Client " & Client.Username & " has been kicked.")
                Exit For
            End If
    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.


Is This A Good Question/Topic? 0
  • +

Page 1 of 1