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 / C++ / MFC
  4. Multithread (Client Server) Problem (Repost)

Multithread (Client Server) Problem (Repost)

Scheduled Pinned Locked Moved C / C++ / MFC
helpsysadminquestion
4 Posts 4 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.
  • H Offline
    H Offline
    hkl
    wrote on last edited by
    #1

    Hi, Can anyone please give me any comment or solution to this situation?? In my program, I've used multithread (many clients) to send message to one thread(Server). However, I realized that only the first client can get access to the server from start to end, other clients are always blocked. Can anyone help me to solve this problem, so that all clients can access the server?? The following is the code of the server: if ( svrSocket.Accept(socket)) AfxMessageBox("Socket is created Succesfully"); while (...) flag = socket.Receive(buff,sizeof(buff)); .... Please HELP! Thank you!!:confused:

    T J L 3 Replies Last reply
    0
    • H hkl

      Hi, Can anyone please give me any comment or solution to this situation?? In my program, I've used multithread (many clients) to send message to one thread(Server). However, I realized that only the first client can get access to the server from start to end, other clients are always blocked. Can anyone help me to solve this problem, so that all clients can access the server?? The following is the code of the server: if ( svrSocket.Accept(socket)) AfxMessageBox("Socket is created Succesfully"); while (...) flag = socket.Receive(buff,sizeof(buff)); .... Please HELP! Thank you!!:confused:

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      If you have the server thread processing the requests for one client in a tight loop, it can't accept other connections. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?

      1 Reply Last reply
      0
      • H hkl

        Hi, Can anyone please give me any comment or solution to this situation?? In my program, I've used multithread (many clients) to send message to one thread(Server). However, I realized that only the first client can get access to the server from start to end, other clients are always blocked. Can anyone help me to solve this problem, so that all clients can access the server?? The following is the code of the server: if ( svrSocket.Accept(socket)) AfxMessageBox("Socket is created Succesfully"); while (...) flag = socket.Receive(buff,sizeof(buff)); .... Please HELP! Thank you!!:confused:

        J Offline
        J Offline
        Jon Hulatt
        wrote on last edited by
        #3

        hkl wrote: flag = socket.Receive(buff,sizeof(buff)); Execution in this thread blocks until Receive can get (sizeof(buff)) bytes of data. You should probably use CAsyncSocket; it would probably meet your requirements better. Jon Sorry to dissapoint you all with my lack of a witty or poignant signature.

        1 Reply Last reply
        0
        • H hkl

          Hi, Can anyone please give me any comment or solution to this situation?? In my program, I've used multithread (many clients) to send message to one thread(Server). However, I realized that only the first client can get access to the server from start to end, other clients are always blocked. Can anyone help me to solve this problem, so that all clients can access the server?? The following is the code of the server: if ( svrSocket.Accept(socket)) AfxMessageBox("Socket is created Succesfully"); while (...) flag = socket.Receive(buff,sizeof(buff)); .... Please HELP! Thank you!!:confused:

          L Offline
          L Offline
          Le centriste
          wrote on last edited by
          #4

          That is because the thread Accept()ing the connection is the same that Receive()s the request on the socket. You must dispatch the socket returned by Accept() first param to another thread, which will Receive(), preventing the server thread from blocking. If you have problem understanding this concept, I suggest that you read this: http://www.codeproject.com/useritems/winsockintro03.asp Michel If I am wrong or said something stupid, I apologize in advance ;)

          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