-
winsock problem...
i would like to wite my own telnet client... but my problem is how to make the program to recv() the data... all the time.
what i mean is how do i now when there is incoming data, so then i could use recv(), because i know that recv() returns zero on connection ternomated, and blocks the connection when there is no incoming data...
what do i do???
thanks guys...
-
One solution is a non-blocking I/O model.
I highly recommend Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohmund.
Kuphryn
-
What I did...
What I did was create a DLL to handle any internet connections I wanted, and I incorporated its own callback functions. So what it does is create a thread per socket, then that thread monitors the socket using WSAWaitForMultipleEvents, and WSAEnumNetworkEvents to find out which activity has occured. Afterwards it just sends that data to a function defined by the Win32 application, then it can use another function in the DLL to read the data when it decides to.
-
In this case, the DLL needs a mean to communicate with the parent process and update the process upon incoming data.
One solution is to update the DLL with a safe handle of the parent process. As an event triggers WaifForMultipleObjects() or events, the DLL sends a message to the parent process.
Kuphryn
-
I think you use "Asyncronous Sockets", I'm not sure of the exact name, but I have some of my winsock code...
Code:
//in your callback function
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {
switch(wMsg) {
case CONNECTION_PENDING:
if(LOWORD(lParam)==8){
//accept
}
break;
case DATA_PENDING:
if(LOWORD(lParam) == FD_CLOSE) {
//disconnecting from client
}
//receive data here
break;
}
}
thats the basic code i use..works well for what i need/use it for