예제 #1
0
파일: client.c 프로젝트: legrajul/bavardage
//Création du socket
int connect_socket (const char *addr, const int port) {
	int co;
	if ((client_sock = creerSocketTCP ()) == NULL) {
		perror ("creerSocketTCP");
		return -1;
	}
	printf ("Please wait for connecting the server...\n");
	if ((co = connectSocketTCP (client_sock, addr, port)) == -1) {
		perror ("connectSocketTCP");
		return -1;
	}

	printf ("You can now send commands and messages\n");
	start_communication ();

	return 0;
}
예제 #2
0
int main(int argc, char **argv) {
	srand(time(NULL));

	struct command_args args = get_args(argc, argv);
	atexit(close_queue);

	key_t key = ftok(args.path, args.id);
	check_failure((int) key, -1, "failed to execute ftok\n");

	ID = msgget(key, IPC_CREAT | 0700);
	check_failure(ID, -1, "failed to execute msgget\n");

	struct q_msg buf;

	while(1) {

		int status;

		status = msgrcv(ID, &buf, size, 1, IPC_NOWAIT);

		if (status > 0) {
			start_communication(buf.msg);
			continue;
		}

		int i;
		for (i = 0; i < client_no; i++) {

			status = msgrcv(clients[i], &buf, size, 2, IPC_NOWAIT);
			if (status > 0) {
				send_random(buf.msg);
			}

			status = msgrcv(clients[i], &buf, size, 3, IPC_NOWAIT);
			if (status > 0) {
				process_response(buf.msg);
			}
		}

	}

	return 0;
}