Hey all. I'm currently writing a basic TCP client script with basic write and read functions implemented. As I understand, it makes sense to enter an infinite while loop to read responses from the server until read returns zero (in which case break; is sent to break out of the while loop). It makes sense in theory. But, whenever read can't find any bytes to read, it just freezes up my program (I assume until it's given bytes to read). So, is there a way to avoid this? I want to use the infinite while loop technique, but it won't work because instead of returning zero or -1 for error, it just freezes everything.

Thanks in advance.

I'm currently trying this:

Code:
while((n = read( sockfd, buffer, 200)) > 0)
	{
		//n = read( sockfd, buffer, 200);
		//if(n == 0 || n == -1) exit(1);
		if(n > 0) buffer[n] = 0;
		printf( buffer );
		printf("%d", n);
		if(n < 1) exit(1);
	}