Пример #1
0
int main(int argc, char *argv[])
{
	//================De aici===============================
	static struct connection *connn;
	char buffer[256];

	wsa_init();//ai nevoie de functia asta in main
	
	connectfd = tcp_connect_to_server(argv[1], atoi(argv[2]));
	DIE(connectfd == INVALID_SOCKET, "tcp_connect_to_server");

	
	/* Instantiate new connection handler. */
	connn = connection_create(connectfd);

	//Aici in primul receive primesti datele gen pozitii initiale
	memcpy(connn->send_buffer,"-1.000000 -1.000000 -324.042542 -0.000003 -305.136108 303.976868 158.605179 -160.047546",75);
	connn->bytes_sent = 3;
	printf("Sent : %s\n",&connn->send_buffer);
	connection_schedule_socket_send(connn);
	Sleep(100);
	connection_schedule_socket_receive(connn);
	printf("buffer : %s\n",connn->recv_buffer);
	//=========================Pana aici===========================
	//=====================trebuie pus in mainul tau======================
	/* client main loop ;acest loop poate fi pus intr-o functie daca vrei*/
	while (1) {
		
		//Astepti comanda de la tastatura
		printf("Please enter the command (or 'quit' to exit): \n");
    	memset(buffer, 0 , 256);
    	fgets(buffer, 255, stdin);

		if (buffer[0]=='q'){
			tcp_close_connection(connn->sockfd);	
			exit(0);
		}

		//Copiezi comanda pentru a o trimite la server
		memcpy(connn->send_buffer,buffer,256);
		connn->bytes_sent = 256;
		printf("Sent : %s\n",&connn->send_buffer);
		connection_schedule_socket_send(connn);
		Sleep(100);
		connection_schedule_socket_receive(connn);
		//desi nu e nevoie acum in buffer e tot ce ai primit de la server
		memcpy(buffer,connn->recv_buffer,256);
		//==========================================
		//Aici poti s afolosesti campul connn->recv_buffer sau buffer pentru a procesa datele tale;eu doar le afisez
		//============================================
		printf("Received: %s\n",&connn->recv_buffer);
		
		
	}

	wsa_cleanup();//ai nevoie de functia asta in main

	return 0;
}
Пример #2
0
static void connection_complete_socket_receive(struct connection *conn, WSAOVERLAPPED *ovp)
{
	BOOL bRet;
	DWORD flags;

	bRet = WSAGetOverlappedResult(
			conn->sockfd,
			ovp,
			&conn->bytes_recv,
			FALSE,
			&flags);
	DIE(bRet == FALSE, "WSAGetOverlappedResult");

	/* In case of no bytes received, consider connection terminated. */
	if (conn->bytes_recv == 0) {
		connection_remove(conn);
		return;
	}

	connection_prepare_socket_send(conn);
	connection_schedule_socket_send(conn);
}