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. Problem with CSocket

Problem with CSocket

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

    I'm trying to figure out why my CSocket.Receive() call is blocking. This is the code I have so far: CSocket socket; //Connect to server socket.Create(); ret = socket.Connect(m_sAddress, m_nPort); //Check for connection errors if (ret == 0) { GetSocketError(); //Get Socket's Last Error return -1; } //__if (ret == 0)__ m_TotalBytes = 0; while(m_bRunThread) { BYTE* pBuffer = new BYTE[MAX_BUFFER_SIZE]; ret = socket.Receive(pBuffer, MAX_BUFFER_SIZE); ........ } The socket connects but never receives any data. The call to Receive seems to block the thread. I know the server program I am using is working because I can transfer data to other clients without a problem. Any suggestions? Thanks

    Z 1 Reply Last reply
    0
    • M masnu

      I'm trying to figure out why my CSocket.Receive() call is blocking. This is the code I have so far: CSocket socket; //Connect to server socket.Create(); ret = socket.Connect(m_sAddress, m_nPort); //Check for connection errors if (ret == 0) { GetSocketError(); //Get Socket's Last Error return -1; } //__if (ret == 0)__ m_TotalBytes = 0; while(m_bRunThread) { BYTE* pBuffer = new BYTE[MAX_BUFFER_SIZE]; ret = socket.Receive(pBuffer, MAX_BUFFER_SIZE); ........ } The socket connects but never receives any data. The call to Receive seems to block the thread. I know the server program I am using is working because I can transfer data to other clients without a problem. Any suggestions? Thanks

      Z Offline
      Z Offline
      Zac Howland
      wrote on last edited by
      #2

      Use CAsyncSocket instead of CSocket. CSocket assumes synchonous communications (that is, you will send, then wait for a return message). An alternative is to put the socket's receive call in a worker thread that fires off an event when it receives data in the buffer. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

      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