|
-
September 21st, 2002, 02:30 PM
#1
Getting Socket Events
Hi,
I have a server/client program that uses winsock (im not using the CSocket class). Is it possible to have a function called when data is recieved by the socket? Thanks
-
September 21st, 2002, 03:41 PM
#2
If you are talking about any kind of event that will occur then the answer is no - at least to my knowledge. and depending on the operating system. In Windows you can work with 'WSA...' events but they are not available on other operating systems...
However you can use the 'select()' function to determine when more data arrives...
Code:
int iRC = 0;
timeval SendTimeout;
// Set timeout
SendTimeout.tv_sec = 0;
SendTimeout.tv_usec = 250000; // 250 ms
fd_set fds;
FD_ZERO(&fds);
FD_SET(Socket, &fds);
iRC = select(0, &fds, NULL, NULL, &SendReceiveTimeout);
if(!iRC)
// Timeout occured
else if(iRC < 0)
// Error -> call 'WSAGetLastError()'
else
// Data arrives
Based on this you can implement some kind of notification on your own...
Last edited by Andreas Masur; September 21st, 2002 at 03:47 PM.
-
September 22nd, 2002, 11:49 AM
#3
Yes. You could call a function to receive data. Receiving data has nothing to do with your software design. Heck, you could call a function in another class to receive data. You just have to pass a handle of the socket to the function.
What I/O model are you using?
Kuphryn
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|