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. Socket Problem...

Socket Problem...

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 2 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, I use the following code: if ( svrSocket.Accept(socket)) AfxMessageBox("Socket is created Succesfully"); flag = socket.Receive(buff,sizeof(buff)); .... Is it true that everytime "socket.Receive(..)" must wait until it actually receives something?? What if I want it to pause the receiving for a small period?? Because it would be simply dead if it never receive anything. Can anyone please give me advance?? Thank you

    J 1 Reply Last reply
    0
    • H hkl

      Hi, I use the following code: if ( svrSocket.Accept(socket)) AfxMessageBox("Socket is created Succesfully"); flag = socket.Receive(buff,sizeof(buff)); .... Is it true that everytime "socket.Receive(..)" must wait until it actually receives something?? What if I want it to pause the receiving for a small period?? Because it would be simply dead if it never receive anything. Can anyone please give me advance?? Thank you

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      Use asynchronous sockets (CAsyncSocket, if you're doing it the MFC way). Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      H 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        Use asynchronous sockets (CAsyncSocket, if you're doing it the MFC way). Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        H Offline
        H Offline
        hkl
        wrote on last edited by
        #3

        Thank you for your reply!!:) Yes, I am doing the MFC way. But the socket cannot receive correctly if I use CAsyncSocket instead of CSocket. Is there a problem of my program?? Or is there another way to do it?? Thanks!

        J 1 Reply Last reply
        0
        • H hkl

          Thank you for your reply!!:) Yes, I am doing the MFC way. But the socket cannot receive correctly if I use CAsyncSocket instead of CSocket. Is there a problem of my program?? Or is there another way to do it?? Thanks!

          J Offline
          J Offline
          Joaquin M Lopez Munoz
          wrote on last edited by
          #4

          The mode of use of CAsyncSocket is different than CSocket. Put briefly, with asynchronous sockets you've got to wait for the socket to tell you that reading/writing is permissible. Check the docs for this class. So I'm afraid you'll have to rewrite portions of your code to change to asynchronous. An alternative ad hoc solution I just ran into is using Tim Kosse's CSocket-Derived Class that Checks for Timeouts, which hopefully can be plugged into your program with minimum effort. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

          H 1 Reply Last reply
          0
          • J Joaquin M Lopez Munoz

            The mode of use of CAsyncSocket is different than CSocket. Put briefly, with asynchronous sockets you've got to wait for the socket to tell you that reading/writing is permissible. Check the docs for this class. So I'm afraid you'll have to rewrite portions of your code to change to asynchronous. An alternative ad hoc solution I just ran into is using Tim Kosse's CSocket-Derived Class that Checks for Timeouts, which hopefully can be plugged into your program with minimum effort. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

            H Offline
            H Offline
            hkl
            wrote on last edited by
            #5

            Great! Thank you!! Let me try that!!:)

            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