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. Reading from a socket

Reading from a socket

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

    I'm just starting to do some socket programming (non-MFC) and had a couple questions. Is there a ReadLine function to read a single line from a socket? If not would a line be terminated by a \r \n or both? Lastly is there a function to "peek" at the data waiting to be read? Like the peekmessage that would allow me to retreive the the waiting data without actually removing it from the socket? Thanks. - Aaron

    U D 2 Replies Last reply
    0
    • M monrobot13

      I'm just starting to do some socket programming (non-MFC) and had a couple questions. Is there a ReadLine function to read a single line from a socket? If not would a line be terminated by a \r \n or both? Lastly is there a function to "peek" at the data waiting to be read? Like the peekmessage that would allow me to retreive the the waiting data without actually removing it from the socket? Thanks. - Aaron

      U Offline
      U Offline
      User 1057324
      wrote on last edited by
      #2

      use the recv function to read from the socket. the recv function can be blocking or non-blocking according to the connection specified... these sockets are known as synchronous sockets but, if u wish to get a notification whenever a message reaches the port , then use asynchronous sockets. there are various options: FD_READ|FD_WRITE|FD_CLOSE|FD_CONNECT , etc etc... u have to use the API: WSAAsyncSelect.... search for the API in MSDN and include the required library and header file.. i think the library is : Ws2_32.lib and header file is winsock2.h , i think winsock.h will also work... u have to create a user defined message: #define MY_MSG WM_USER + 100 OR something.... as u wish... this is one of the arguments in the API call.... we can achieve this also using synchronous sockets , but asynchronous is much more easy....

      1 Reply Last reply
      0
      • M monrobot13

        I'm just starting to do some socket programming (non-MFC) and had a couple questions. Is there a ReadLine function to read a single line from a socket? If not would a line be terminated by a \r \n or both? Lastly is there a function to "peek" at the data waiting to be read? Like the peekmessage that would allow me to retreive the the waiting data without actually removing it from the socket? Thanks. - Aaron

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        monrobot13 wrote: Is there a ReadLine function to read a single line from a socket? To my knowledge, sockets do not know what "lines" are. That is a notion understood by us, and some text editors. monrobot13 wrote: Lastly is there a function to "peek" at the data waiting to be read?

        ioctlsocket(..., FIONREAD, ...);

        is but one way.


        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

        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