Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Client/Server TCPClient

Client/Server TCPClient

Scheduled Pinned Locked Moved C#
sysadminhelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlexDuta
    wrote on last edited by
    #1

    Hi, I developed an Client / Server application, the problem is the following: - when a wrong IP address is inserted in the Textbox, Client application freeze.

    TcpClient socketForServer;
    try
    {
    socketForServer = new TcpClient(Ip, Port);
    }
    catch (Exception e1) {
    info._error = e1.ToString();
    return info;
    }

    What I can do?

    T A 2 Replies Last reply
    0
    • A AlexDuta

      Hi, I developed an Client / Server application, the problem is the following: - when a wrong IP address is inserted in the Textbox, Client application freeze.

      TcpClient socketForServer;
      try
      {
      socketForServer = new TcpClient(Ip, Port);
      }
      catch (Exception e1) {
      info._error = e1.ToString();
      return info;
      }

      What I can do?

      T Offline
      T Offline
      terradtc
      wrote on last edited by
      #2

      You will want to start running your TCPClient on a different Thread so it doesn't lock up the GUI thread while waiting for a timeout or connection refused. So do the following ThreadPool.QueueUserWorkItem(new WaitCallback()); Keep in mind that the Drawing of items can only be done on the thread they were created on (usually the main thread) so setting text and that sort of thing should be done by invoking the functions using the Invoke function

      T A 2 Replies Last reply
      0
      • T terradtc

        You will want to start running your TCPClient on a different Thread so it doesn't lock up the GUI thread while waiting for a timeout or connection refused. So do the following ThreadPool.QueueUserWorkItem(new WaitCallback()); Keep in mind that the Drawing of items can only be done on the thread they were created on (usually the main thread) so setting text and that sort of thing should be done by invoking the functions using the Invoke function

        T Offline
        T Offline
        terradtc
        wrote on last edited by
        #3

        Alternatively you can also use the asynchronous methods of TCP client to make your connection, BeginConnect and EndConnect

        1 Reply Last reply
        0
        • T terradtc

          You will want to start running your TCPClient on a different Thread so it doesn't lock up the GUI thread while waiting for a timeout or connection refused. So do the following ThreadPool.QueueUserWorkItem(new WaitCallback()); Keep in mind that the Drawing of items can only be done on the thread they were created on (usually the main thread) so setting text and that sort of thing should be done by invoking the functions using the Invoke function

          A Offline
          A Offline
          AlexDuta
          wrote on last edited by
          #4

          Ty for replay.

          1 Reply Last reply
          0
          • A AlexDuta

            Hi, I developed an Client / Server application, the problem is the following: - when a wrong IP address is inserted in the Textbox, Client application freeze.

            TcpClient socketForServer;
            try
            {
            socketForServer = new TcpClient(Ip, Port);
            }
            catch (Exception e1) {
            info._error = e1.ToString();
            return info;
            }

            What I can do?

            A Offline
            A Offline
            AhsanS
            wrote on last edited by
            #5

            there are couple of things that you may do 1. Application.DoEvents() 2. You need to set socketForServer to null in case an error occurs, it will be creating a new object every time and will become a source of memory leak.

            Ahsan Ullah Senior Software Engineer MCTS 2.0

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups