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. Program hangs...

Program hangs...

Scheduled Pinned Locked Moved C#
winformssysadminhelpquestion
10 Posts 7 Posters 1 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
    ayandelhi
    wrote on last edited by
    #1

    Hi!! Its good to be back... I'm working on a simple client server program... server waits for connection and client sends request for connection sort of... simple... On the same m/c but when i start my program... it hangs... it displays all msgs and then hangs.. doesnt respond to anything... then i start my client it connects to the server but server aint responding... i'm using windows forms in place of console app as per tutorials... plz help me... should i attach my code here???

    S R H L realJSOPR 6 Replies Last reply
    0
    • A ayandelhi

      Hi!! Its good to be back... I'm working on a simple client server program... server waits for connection and client sends request for connection sort of... simple... On the same m/c but when i start my program... it hangs... it displays all msgs and then hangs.. doesnt respond to anything... then i start my client it connects to the server but server aint responding... i'm using windows forms in place of console app as per tutorials... plz help me... should i attach my code here???

      S Offline
      S Offline
      ScottM1
      wrote on last edited by
      #2

      Have you got a firewall enabled? Attach snippets of your client and server code so we can see what you're doing.

      1 Reply Last reply
      0
      • A ayandelhi

        Hi!! Its good to be back... I'm working on a simple client server program... server waits for connection and client sends request for connection sort of... simple... On the same m/c but when i start my program... it hangs... it displays all msgs and then hangs.. doesnt respond to anything... then i start my client it connects to the server but server aint responding... i'm using windows forms in place of console app as per tutorials... plz help me... should i attach my code here???

        R Offline
        R Offline
        Rajesh Anuhya
        wrote on last edited by
        #3

        check your server call back function is correct or not.., i think that is the problem, that's way you are able the receive the data for very first time of each new client.

        Rajesh B --> A Poor Workman Blames His Tools <--

        1 Reply Last reply
        0
        • A ayandelhi

          Hi!! Its good to be back... I'm working on a simple client server program... server waits for connection and client sends request for connection sort of... simple... On the same m/c but when i start my program... it hangs... it displays all msgs and then hangs.. doesnt respond to anything... then i start my client it connects to the server but server aint responding... i'm using windows forms in place of console app as per tutorials... plz help me... should i attach my code here???

          H Offline
          H Offline
          Harvey Saayman
          wrote on last edited by
          #4

          Whats hanging? The server or client application? Are your listeners and tcp stuff in seperate threads or just running on the UI thread? Are you using blocking or not blocking methods? You really need to give us some code to look at here...

          My Band

          1 Reply Last reply
          0
          • A ayandelhi

            Hi!! Its good to be back... I'm working on a simple client server program... server waits for connection and client sends request for connection sort of... simple... On the same m/c but when i start my program... it hangs... it displays all msgs and then hangs.. doesnt respond to anything... then i start my client it connects to the server but server aint responding... i'm using windows forms in place of console app as per tutorials... plz help me... should i attach my code here???

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            you should not execute blocking calls on the main thread; either use asynchronous methods, or better yet apply proper threading. There are some CP articles on threaded client-server systems. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            1 Reply Last reply
            0
            • A ayandelhi

              Hi!! Its good to be back... I'm working on a simple client server program... server waits for connection and client sends request for connection sort of... simple... On the same m/c but when i start my program... it hangs... it displays all msgs and then hangs.. doesnt respond to anything... then i start my client it connects to the server but server aint responding... i'm using windows forms in place of console app as per tutorials... plz help me... should i attach my code here???

              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #6

              Is the listener running in its own thread? It should be.

              .45 ACP - because shooting twice is just silly
              -----
              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

              1 Reply Last reply
              0
              • A ayandelhi

                Hi!! Its good to be back... I'm working on a simple client server program... server waits for connection and client sends request for connection sort of... simple... On the same m/c but when i start my program... it hangs... it displays all msgs and then hangs.. doesnt respond to anything... then i start my client it connects to the server but server aint responding... i'm using windows forms in place of console app as per tutorials... plz help me... should i attach my code here???

                A Offline
                A Offline
                ayandelhi
                wrote on last edited by
                #7

                This is the complete source code for my server side program... on clicking the button it calls func conn_man.. on clicking it this program hangs... b4 clicking it.. the program is responding n i can move it resize it n stuff.. but after the button is clicked its not responding.. plz.. tell me how to get it working.. on receiving the connection from client it searches for a free port on the server it self.. when found it sends the client the free port to connect to[ function route does it].. master_slave is another form which is called on accepting a connection from client

                namespace master
                {
                public partial class main_form : Form
                {
                public int port;
                public main_form()
                {
                InitializeComponent();
                activity_win.AppendText("Master On...");
                }

                    public void conn\_man()
                    {
                        try
                        {
                            //activity\_win.AppendText("In conn\_man...");
                            IPAddress ipAd = IPAddress.Parse("192.168.1.2");
                            // use local m/c IP address, and 
                            // use the same in the client
                            /\* Initializes the Listener \*/
                            TcpListener listener = new TcpListener(ipAd, 5000);
                            /\* Start Listeneting at the specified port \*/
                            listener.Start();
                            activity\_win.AppendText("\\r\\nThe server is running at port 5000...");
                            activity\_win.AppendText("\\r\\nThe local End point is  :" + listener.LocalEndpoint);
                            activity\_win.AppendText("\\r\\nWaiting for a connection.....");
                            Socket s = listener.AcceptSocket();
                            activity\_win.AppendText("\\r\\nConnection accepted from " + s.RemoteEndPoint);
                            byte\[\] b = new byte\[100\];
                            int k = s.Receive(b);
                            activity\_win.AppendText("Recieved...");
                            activity\_win.AppendText(ASCIIEncoding.ASCII.GetString(b));
                            if (route(5000) == 0)
                            {
                                activity\_win.AppendText("No port free");
                                ASCIIEncoding asen = new ASCIIEncoding();
                                s.Send(asen.GetBytes("Busy"));
                            }
                            else
                            {
                                port = route(5000);
                                new master\_slave(port);
                                ASCIIEncoding asen = new ASCIIEncoding();
                                s.Send(asen.GetBytes("Port " + port.ToString()));
                            }
                            /\* clean up \*/
                
                A P 2 Replies Last reply
                0
                • A ayandelhi

                  This is the complete source code for my server side program... on clicking the button it calls func conn_man.. on clicking it this program hangs... b4 clicking it.. the program is responding n i can move it resize it n stuff.. but after the button is clicked its not responding.. plz.. tell me how to get it working.. on receiving the connection from client it searches for a free port on the server it self.. when found it sends the client the free port to connect to[ function route does it].. master_slave is another form which is called on accepting a connection from client

                  namespace master
                  {
                  public partial class main_form : Form
                  {
                  public int port;
                  public main_form()
                  {
                  InitializeComponent();
                  activity_win.AppendText("Master On...");
                  }

                      public void conn\_man()
                      {
                          try
                          {
                              //activity\_win.AppendText("In conn\_man...");
                              IPAddress ipAd = IPAddress.Parse("192.168.1.2");
                              // use local m/c IP address, and 
                              // use the same in the client
                              /\* Initializes the Listener \*/
                              TcpListener listener = new TcpListener(ipAd, 5000);
                              /\* Start Listeneting at the specified port \*/
                              listener.Start();
                              activity\_win.AppendText("\\r\\nThe server is running at port 5000...");
                              activity\_win.AppendText("\\r\\nThe local End point is  :" + listener.LocalEndpoint);
                              activity\_win.AppendText("\\r\\nWaiting for a connection.....");
                              Socket s = listener.AcceptSocket();
                              activity\_win.AppendText("\\r\\nConnection accepted from " + s.RemoteEndPoint);
                              byte\[\] b = new byte\[100\];
                              int k = s.Receive(b);
                              activity\_win.AppendText("Recieved...");
                              activity\_win.AppendText(ASCIIEncoding.ASCII.GetString(b));
                              if (route(5000) == 0)
                              {
                                  activity\_win.AppendText("No port free");
                                  ASCIIEncoding asen = new ASCIIEncoding();
                                  s.Send(asen.GetBytes("Busy"));
                              }
                              else
                              {
                                  port = route(5000);
                                  new master\_slave(port);
                                  ASCIIEncoding asen = new ASCIIEncoding();
                                  s.Send(asen.GetBytes("Port " + port.ToString()));
                              }
                              /\* clean up \*/
                  
                  A Offline
                  A Offline
                  ayandelhi
                  wrote on last edited by
                  #8

                  The same code is working fine as a console app... i changed a lil bit in route func.. due to an logical problem... rest is same.. its working in console app... Y??? Wats the error or problematic statement in this code...

                  1 Reply Last reply
                  0
                  • A ayandelhi

                    This is the complete source code for my server side program... on clicking the button it calls func conn_man.. on clicking it this program hangs... b4 clicking it.. the program is responding n i can move it resize it n stuff.. but after the button is clicked its not responding.. plz.. tell me how to get it working.. on receiving the connection from client it searches for a free port on the server it self.. when found it sends the client the free port to connect to[ function route does it].. master_slave is another form which is called on accepting a connection from client

                    namespace master
                    {
                    public partial class main_form : Form
                    {
                    public int port;
                    public main_form()
                    {
                    InitializeComponent();
                    activity_win.AppendText("Master On...");
                    }

                        public void conn\_man()
                        {
                            try
                            {
                                //activity\_win.AppendText("In conn\_man...");
                                IPAddress ipAd = IPAddress.Parse("192.168.1.2");
                                // use local m/c IP address, and 
                                // use the same in the client
                                /\* Initializes the Listener \*/
                                TcpListener listener = new TcpListener(ipAd, 5000);
                                /\* Start Listeneting at the specified port \*/
                                listener.Start();
                                activity\_win.AppendText("\\r\\nThe server is running at port 5000...");
                                activity\_win.AppendText("\\r\\nThe local End point is  :" + listener.LocalEndpoint);
                                activity\_win.AppendText("\\r\\nWaiting for a connection.....");
                                Socket s = listener.AcceptSocket();
                                activity\_win.AppendText("\\r\\nConnection accepted from " + s.RemoteEndPoint);
                                byte\[\] b = new byte\[100\];
                                int k = s.Receive(b);
                                activity\_win.AppendText("Recieved...");
                                activity\_win.AppendText(ASCIIEncoding.ASCII.GetString(b));
                                if (route(5000) == 0)
                                {
                                    activity\_win.AppendText("No port free");
                                    ASCIIEncoding asen = new ASCIIEncoding();
                                    s.Send(asen.GetBytes("Busy"));
                                }
                                else
                                {
                                    port = route(5000);
                                    new master\_slave(port);
                                    ASCIIEncoding asen = new ASCIIEncoding();
                                    s.Send(asen.GetBytes("Port " + port.ToString()));
                                }
                                /\* clean up \*/
                    
                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    Why are you doing everything on the primary thread?

                    I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

                    Forgive your enemies - it messes with their heads

                    My blog | My articles | MoXAML PowerToys | Onyx

                    A 1 Reply Last reply
                    0
                    • P Pete OHanlon

                      Why are you doing everything on the primary thread?

                      I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

                      Forgive your enemies - it messes with their heads

                      My blog | My articles | MoXAML PowerToys | Onyx

                      A Offline
                      A Offline
                      ayandelhi
                      wrote on last edited by
                      #10

                      can u plz tell me... the number of threads n what shud it do?? for my program...

                      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