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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. TCP Socket Problems

TCP Socket Problems

Scheduled Pinned Locked Moved C#
helpsysadminannouncement
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.
  • C Offline
    C Offline
    c guy3811
    wrote on last edited by
    #1

    I have a client/server relationship which I use to update files on connected users' computers. It uses Asynchronous Socket operations and sends binary data over TCP sockets. The connections are maintained indefinately until the client or server disconnects, or a client encounters an error and closes the connection. The problem I am having is that after a few days, the server stops sending messages to its clients. The number of clients right now is about 20-25, which are connected at all times. I see from the message logs that it is receiveing client requests, but it is not sending a response to those clients. The server is set to send updates at 12:30 AM every day, but after about 4 days it stops sending anything. I know it would be helpful to have the code, but not knowing where exactly the problem is, it is hard to post code, and there is A LOT of it. Any ideas on what the problem may be are appreciated. Thanks in advance!

    I M 3 Replies Last reply
    0
    • C c guy3811

      I have a client/server relationship which I use to update files on connected users' computers. It uses Asynchronous Socket operations and sends binary data over TCP sockets. The connections are maintained indefinately until the client or server disconnects, or a client encounters an error and closes the connection. The problem I am having is that after a few days, the server stops sending messages to its clients. The number of clients right now is about 20-25, which are connected at all times. I see from the message logs that it is receiveing client requests, but it is not sending a response to those clients. The server is set to send updates at 12:30 AM every day, but after about 4 days it stops sending anything. I know it would be helpful to have the code, but not knowing where exactly the problem is, it is hard to post code, and there is A LOT of it. Any ideas on what the problem may be are appreciated. Thanks in advance!

      I Offline
      I Offline
      Ista
      wrote on last edited by
      #2

      I fixed this problem once. I can't remember the solution, but I think I had a thread to keep it alive. Becuase the CLR tries to shut it down after a certain period of time. Nick I'm not an expert yet, but I play one at work. Yeah and here too.

      1 Reply Last reply
      0
      • C c guy3811

        I have a client/server relationship which I use to update files on connected users' computers. It uses Asynchronous Socket operations and sends binary data over TCP sockets. The connections are maintained indefinately until the client or server disconnects, or a client encounters an error and closes the connection. The problem I am having is that after a few days, the server stops sending messages to its clients. The number of clients right now is about 20-25, which are connected at all times. I see from the message logs that it is receiveing client requests, but it is not sending a response to those clients. The server is set to send updates at 12:30 AM every day, but after about 4 days it stops sending anything. I know it would be helpful to have the code, but not knowing where exactly the problem is, it is hard to post code, and there is A LOT of it. Any ideas on what the problem may be are appreciated. Thanks in advance!

        I Offline
        I Offline
        Ista
        wrote on last edited by
        #3

        I would also attach and event counters to it, to see if the OS is shutting it down and something sporadic isd happening. I'm not an expert yet, but I play one at work. Yeah and here too.

        1 Reply Last reply
        0
        • C c guy3811

          I have a client/server relationship which I use to update files on connected users' computers. It uses Asynchronous Socket operations and sends binary data over TCP sockets. The connections are maintained indefinately until the client or server disconnects, or a client encounters an error and closes the connection. The problem I am having is that after a few days, the server stops sending messages to its clients. The number of clients right now is about 20-25, which are connected at all times. I see from the message logs that it is receiveing client requests, but it is not sending a response to those clients. The server is set to send updates at 12:30 AM every day, but after about 4 days it stops sending anything. I know it would be helpful to have the code, but not knowing where exactly the problem is, it is hard to post code, and there is A LOT of it. Any ideas on what the problem may be are appreciated. Thanks in advance!

          M Offline
          M Offline
          mcljava
          wrote on last edited by
          #4

          Beware of IP address changes. If your clients are DHCP based and the IP resets at somepoint during your conenction then you will have a problem. For example if your DHCP address lease is for 3 days then you might want to visit that. Also, make sure your read logic in the server and client is looking for its corresponding peer to drop. I.E. if recv() returns 0 or if a SocketException occurs, depending on how your code is structured. The application should free up any socket related resources and return to a steady state. For the server, this means listebing for new connections. For the client, either exiting or initiating a connection retry sequence. Finally have you stress tested your server? How long can it sustain a constant message flow? If the answer is not indefinitely then you might want to revist the server code to make it moe robust. If it were me, I would make sure the server is 100% bullet proof under load to understand how it performs and what to expect in terms of client communication. Remember any test harness you build should use the same client connection logic. Once you nail that down consider creating a library so that you can build client applications w/o fussing with the connection details. Mike Luster

          C 1 Reply Last reply
          0
          • M mcljava

            Beware of IP address changes. If your clients are DHCP based and the IP resets at somepoint during your conenction then you will have a problem. For example if your DHCP address lease is for 3 days then you might want to visit that. Also, make sure your read logic in the server and client is looking for its corresponding peer to drop. I.E. if recv() returns 0 or if a SocketException occurs, depending on how your code is structured. The application should free up any socket related resources and return to a steady state. For the server, this means listebing for new connections. For the client, either exiting or initiating a connection retry sequence. Finally have you stress tested your server? How long can it sustain a constant message flow? If the answer is not indefinitely then you might want to revist the server code to make it moe robust. If it were me, I would make sure the server is 100% bullet proof under load to understand how it performs and what to expect in terms of client communication. Remember any test harness you build should use the same client connection logic. Once you nail that down consider creating a library so that you can build client applications w/o fussing with the connection details. Mike Luster

            C Offline
            C Offline
            c guy3811
            wrote on last edited by
            #5

            The clients and servers both use a .dll for connection/send/rcv data. The server assigns the new socket to an ArrayList when a client connects, and gives the client an associated number. When a client disconnects, the server removes the client at the ClientNumber position in the ArrayList, then updates all necessary ClientNumbers to the correct position. While the update is going on, the server is suspended, IE, it can not accept new connections until the update is complete. The client dll backend catches an error, performs cleanup procedures, then trys to reconnect at a random interval. The connect/disconnect portion of the program isnt the problem. Even when the server hangs it still accepts/disconnects. IP Addresses are static. That shouldnt be a problem. Im beginning to think that it may be some of the other software running on the actual server with my server program. I think the backup software is locking the database when the server tries to update file listings. When I came in this morning, the ListView telling me what the current files were was empty, suggesting it failed contacting the database. If that is the case, then when it tries sending files, it wont have any references in the DataSets, and will simply return from the function without sending anything. Ill keep everyone informed incase the problem may come up with someone else.

            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