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 / C++ / MFC
  4. Socket

Socket

Scheduled Pinned Locked Moved C / C++ / MFC
sysadmin
2 Posts 2 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.
  • S Offline
    S Offline
    shakumar_22
    wrote on last edited by
    #1

    Hi to all Anybody give me the suggestion og reuse of Socket. In my socket programme,server will receive the client in server socket , to disconnect the client i used socket shutdown and close to disconnect the client.After another client can connect to the server but they cannot transfer the data between them.This is multi threading programme. (As my knowledge shutdown and close option is completly end the socket therfore we must restart the socket.) Give me the suggestion to solve this.

    shakumar

    N 1 Reply Last reply
    0
    • S shakumar_22

      Hi to all Anybody give me the suggestion og reuse of Socket. In my socket programme,server will receive the client in server socket , to disconnect the client i used socket shutdown and close to disconnect the client.After another client can connect to the server but they cannot transfer the data between them.This is multi threading programme. (As my knowledge shutdown and close option is completly end the socket therfore we must restart the socket.) Give me the suggestion to solve this.

      shakumar

      N Offline
      N Offline
      Nuxser
      wrote on last edited by
      #2

      Not very clear about your problem from your post. Generally, for a server process you will, 1. Initialize Winsock 2. Create a socket and bind it to network interface and port. NOTE: This is the listening socket 3. Then, you can say, prepare the socket to listen for connection request in that socket 4. Then you wait on that socket for incoming connection by accept(..) call. When this call returns, it will return a new socket where the client is connected. Note that the original listen socket is not used by the connection. You take the new socket returned by accept(..) and do you communication and finally close it. You must not close the socket on which you are listening. So in that regards, I am not sure in your post, which socket you are closing. (Even if you are using Unix/Linux the concept remains the same as they are POSIX sockets) Look at the example given in the link: http://msdn2.microsoft.com/en-us/library/ms737526.aspx Within the example, once accept has return with a valid connected socket (a.k.a the 'else' portion of the check) you can initiate a thread where you will use the socket to do your stuff with the client and close the socket. You only close the socket you are listening on, when you terminate the server app or you do not wish to listen for connection on that socket any more. -- Soyuz -- modified at 1:45 Thursday 5th July, 2007 Wanted to add that, once accept(...) returns, and you deal with you client (either by initiating a separate thread or in the same thread) you need to go back to wait on accept(...) again to server other incoming request. With the close & shutdown call, I remember an issue about the TCP/IP stack taking some time to actually making the socket available for further reuse and the workaround was (as far as I remember) to set socket option to socket reuse.

      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