All pastes #18129 Raw Edit

Mine

public cpp v1 · immutable
#18129 ·published 2005-07-20 14:04 UTC
rendered paste body
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////client#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <unistd.h>#include <stdio.h>#include <string.h>#include <iostream>using namespace std;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void envoyer(char *msg);void recevoir();////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////struct sockaddr_in  InfoSocket;socklen_t  SocketClient;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int main (){	SocketClient = socket(AF_INET, SOCK_STREAM, 0);	if (SocketClient < 0)	{	cout<<"le socket n'a pu etre crée"<<endl;	return 0;	}	InfoSocket.sin_family = AF_INET;	InfoSocket.sin_port = htons(3400); 	InfoSocket.sin_addr.s_addr = inet_addr("127.0.0.1"); 	memset(&(InfoSocket.sin_zero), 0, 8);	if(connect(SocketClient, (struct sockaddr *)&InfoSocket, sizeof(InfoSocket)) < 0)	{	cout<<"connection imposible"<<endl;	return 0;	}	else	{	cout<<"connection etablie"<<endl;	}	recevoir();	shutdown(SocketClient, 2);	return 0;}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void envoyer(char *msg){	int control = send(SocketClient, msg, strlen(msg), 0);	if (control != strlen(msg))	{		cout<<"erreur: pb dans l'envoy du msg"<<endl;	}}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void recevoir(){	char msg[55];	int control = recv(SocketClient, msg, sizeof(msg), 0);					msg[control]='\0';	if ( control != strlen(msg))	{		cout<<"erreur: pb dans la reception du msg --> Recu: "<<control			<<" attendu: "<<strlen(msg)<<endl;	}		cout<<"Message recu: "<<msg<<endl;}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////