Example #1
0
File: time_cli.c Project: al13n/TCP
void connectToServer(char *addr){

	struct sockaddr_in	servaddr;
	char err_s[MAXLINE];

	if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
		err_sys("socket error");

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port   = htons(ECHO_SRV_PORT);	/* echo server */

	if (inet_pton(AF_INET, addr, &servaddr.sin_addr) <= 0){
		snprintf(err_s, sizeof(err_s), "inet_pton error for %s", addr);
		writeToPipe(err_s);
		err_quit(err_s);
	}
		

	if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0){
		snprintf(err_s, sizeof(err_s), "connect error");
		writeToPipe(err_s);
		err_sys(err_s);
	}

	return;	
}
Example #2
0
void QVFbMouseLinuxTP::sendMouseData(const QPoint &pos, int buttons, int)
{
    if (buttons & Qt::LeftButton) {
        // press
        repeater->start(5);
        writeToPipe(pos, 1);
        lastPos = pos;
    } else {
        // release
        if (lastPos == QPoint(-1,-1))
            return; /* only send one release */
        repeater->stop();
        writeToPipe(pos, 0);
        lastPos = QPoint(-1,-1);
    }
}
int listenSocketWriteToPipeLoop()
{
	int iResult = 0;
	char recvbuf[DEFAULT_BUFLEN];
	int recvbuflen = DEFAULT_BUFLEN;

	// Receive until the peer shuts down the connection
	do {
		ZeroMemory(&recvbuf, recvbuflen);
		iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
		if (iResult > 0) {
			writeToPipe(recvbuf);
		}
		else if (iResult == 0) {
			printf("Connection closing...\n");
			if (!isForceQuit) {
				closesocket(ClientSocket);
				WSACleanup();
			}
			break;
		} else {
			printf("recv failed with error: %d\n", WSAGetLastError());
			if (!isForceQuit) {
				closesocket(ClientSocket);
				WSACleanup();
			}
			return 1;
		}

	} while (iResult > 0);

	return 0;
}
Example #4
0
File: time_cli.c Project: al13n/TCP
void getTime(){
	char recvline[MAXLINE];
	int n;

	while ( (n = Readline(sockfd, recvline, MAXLINE)) >= 0)
	{
		if( n == 0 ){
			snprintf(recvline, sizeof(recvline), "Server terminated prematurely");
			writeToPipe(recvline);
			return ;
		}
		Fputs(recvline, stdout);
	}
}
Example #5
0
void QVFbMouseLinuxTP::repeatLastPress()
{
    writeToPipe(lastPos, 1);
}