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