WinSock 1.1 problem

Started by
3 comments, last by SiCrane 18 years, 8 months ago
Hi there! I use WinSock version 1.1 and I have simply problem. How can I test if some data are on port? Beacouse if I try receive data from server and stream is empty my application freeze for half minute.
Advertisement
You should look into Asynchronous sockets. They don't wait for data to come so your application wouldn't freeze while waiting for data.
You can use the select() function with a TIMEVAL of {0, 0} to check if data is on a socket, or you can use non-blocking sockets so the recv() returns immediately.
Quote:Original post by SiCrane
You can use the select() function with a TIMEVAL of {0, 0} to check if data is on a socket, or you can use non-blocking sockets so the recv() returns immediately.


is this code right? If I used it, it returned only true

bool next_data(SOCKET * theSocket){	fd_set ready;	struct timeval to;	FD_ZERO(&ready);	FD_SET(*theSocket, &ready);	to.tv_sec = 0;	to.tv_usec = 0;		if (select(*theSocket, &ready, 0, 0, &to) < 0) return false;	return true;}
The return value for select() is 0 if the operation timed out, the number of socket handles that are ready if the operation didn't time out or SOCKET_ERROR if there is a problem. Right now your function doesn't seem to be checking for any of those values.

You can try using FD_ISSET() for your socket that you want to check for data on instead of relying on the return value of select, and then only check the return value against SOCKET_ERROR.

This topic is closed to new replies.

Advertisement