none
[VB.NET] TCPClient is not ''UPDATING'' graphics RRS feed

  • Question

  • Hey,

    I'm actually creating a simple chat application (winforms)

    The client is always trying to connect to the server if it is not already (code :)

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    
            Try
                        TCPClientz = New Sockets.TcpClient("127.0.0.1", 8882)
                        TCPClientStream = TCPClientz.GetStream()
    
    Catch x As Exception
                    End Try
    
        End Sub

    Once the client is connected to the server, (I can make ''travel'' text) The client is lagging like crazy, the visual interface is totally slow

    This is the code of the timer which is taking the data from the server : 

    Private Sub checkreceived_Tick(sender As Object, e As EventArgs) Handles checkreceived.Tick
    
            Try
                Dim rcvbytes(TCPClientz.ReceiveBufferSize) As Byte
                TCPClientStream.Read(rcvbytes, 0, CInt(TCPClientz.ReceiveBufferSize))
                Dim encoding As System.Text.Encoding = System.Text.Encoding.Unicode
               received = encoding.GetString(rcvbytes)
    
            Catch x As Exception
            End Try
    
        End Sub

    All is working great but thing is slowing me down. I already thought to multithread my app but I didn't found how to thead a timer ...

    If someone know 

    y0ga.

    Monday, March 5, 2018 10:19 AM

All replies

  • The Forms Timer component has a minimum resolution of about 50ms so that's where all the delay is coming in. 

    So in short, this isn't going to work.  Please refer back to your other thread for help in getting a TCP client/server chat app to work.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, March 5, 2018 12:39 PM
    Moderator
  • Thanks for your response but :

    I am not sure to understand...

    I was not talking about the data transfert delay but about my form events : example I wan't programmatically (and internally (not because of a certain received data)) to change my form's size... while my client is connected it is "lagging" and the size is only changing a few moment after. (4 or 5 sec later)


    • Edited by y0ga Monday, March 5, 2018 6:21 PM
    Monday, March 5, 2018 6:20 PM
  • Once your client is connected to the server your timer is still running trying to connect and connect and connect and connect and on and on. I've never seen a TCP Client run that way. I figure something is amiss on how you are attempting to use a TCP Client.

    If you did that with threading instead and constantly launched new threads with TCP Clients all trying to connect to the server that would be bad too.

    Your server code should be listening for incoming calls from a client and once a link is established from the client calling the server the link stays up until the client disconnects typically.

    Quit using timers as they serve no purpose in this scenario.


    La vida loca

    Tuesday, March 6, 2018 3:36 AM