Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I'm studying Window Sockets in C and writing a multiplexing i/o client-server application I'm tryting to deal with Standard Threads. I want to checkactivity in
stdin, stdout and stderr
but It seems I can't get how it works. Input thread it's, for example, when I use printf function or open some file (fopen,fopen_s), output - reading a message from serverby client, reading strings from fileand errorthread -just checking of errors (using fprintf(errno, "param2", param3).

What I have tried:

I want to check activity of this Threadsand I'm writing a programm just to see how it works but I met some issus.I don't understand how to check this activity (yes, maybe it soundsstupid but I really stucked with that).

I wanna do that using select() function and then FD_ZERO and FD_SET. How should I get which socket is active and which is not? How to make themactive?

Here is my "scelet" code:
<pre>	#pragma comment(lib, "ws2_32.lib")
	#define _WINSOCK_DEPRECATED_NO_WARNINGS
	#include <winsock2.h>
	#include <stdio.h>
	#include <stdlib.h>
	#include <errno.h> 
	#include <sys/types.h>

	#define BUFFERSIZE 64
	#define PORT 3765
	#define SERVERADDR argv[1]

	int main(int argc, char *argv[])
	{
	
		struct sockaddr_in serverAddr = { 0 };
		fd_set readSD;
		fd_set writeSD;
		fd_set errorSD;
		timeval tv;
		int retVal;
	
		char msg = '1';
	
		FD_ZERO(&readSD);
		FD_ZERO(&writeSD);
		FD_ZERO(&errorSD);
		FD_SET(msg, &readSD);
		FD_SET(msg, &writeSD);
		FD_SET(msg, &errorSD);
	
		tv.tv_sec = 5;
		retVal = select(msg + 1, &readSD, &writeSD, &errorSD, &tv);
		if (retVal < 0)
		{
			printf("Error\n");
			return -1;
		}
		else if (retVal == 0)
		{
			printf("There is nobody, sorry\n");
		}
		else
		{
			int fd_isset_r = FD_ISSET(msg, &readSD);
			if ((fd_isset_r)!=0)
			{
				printf("fd_isset_r error\n");
			}
			else
			{
				printf("readSD is %s \n", FD_ISSET(msg, &readSD) ? "ready" : "not ready");
			}

			int fd_isset_w = FD_ISSET(msg, &writeSD);
			if ((fd_isset_w) != 0)
			{
				printf("fd_isset_w error\n");
			}
			else
			{
				printf("writeSD is %s\n", FD_ISSET(msg, &writeSD) ? "ready" : "not ready");
			}

			int fd_isset_er = FD_ISSET(msg, &errorSD);
			if ((fd_isset_er) != 0)
			{
				printf("fd_isset_er error\n");
			}
			else
			{
				printf("errorSD is %s\n", FD_ISSET(msg, &errorSD) ? "ready" : "not ready");
			}
		}
		system("pause");
		return 0;
	}



I aprreciate any advices and help. Thanks
Posted
Updated 25-Apr-17 4:46am
v2

1 solution

For learning client/server architecture you better read this article or watch that video. This gives you better insight of real life client/server programming.

The standard I/O are system constants which are working with the PC hardware and working on the FIFO principle.
 
Share this answer
 
Comments
GeorgeZv 27-Apr-17 16:17pm    
Thank you! I found this article very useful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900