| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 
 |  
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <stdio.h>
 #include <string.h>
 #include <netinet/in.h>
 #include <unistd.h>
 #include <stdlib.h>
 
int main(int argc, char * argv[])
{
	struct sockaddr_in    	adr_in;
	int prise , new_prise;
 
	memset((char *) &adr_in, 0, sizeof(adr_in));
	adr_in.sin_family      	= AF_INET;
	adr_in.sin_port        	= htons(6868);   /* numero du port	*/
	adr_in.sin_addr.s_addr 	= htonl(INADDR_ANY);
	//creation de la socket d'attente
	if ((prise = socket(AF_INET, SOCK_STREAM, 0)) < 0)
	{
		perror("Erreur Socket");
		exit(3);
	}
 
	if (bind(prise,(struct sockaddr *) &adr_in, sizeof(adr_in)) != 0)
	{
		perror("Erreur Bind");
		exit(6);
	}
 
	if (listen(prise, 5) != 0)
	{
	perror("Erreur Listen");
	exit(8);
	}
 
	if ((new_prise = accept(prise, NULL, NULL)) == -1)
	{
		perror("Erreur Accept");
		exit(10);
	}
	write ( new_prise , "hello\n",6);
 
 
	close ( new_prise);
	close ( prise ) ;
 
return 0;
} | 
Partager