1 2 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 51
| //serveur
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <strings.h>
typedef struct sockaddr_in sockaddr_in;
typedef struct sockaddr sockaddr;
int main()
{
int serveur;
int client;
sockaddr_in confs;
sockaddr_in confc;
confs.sin_family = AF_INET;
confs.sin_addr.s_addr = inet_addr("127.0.0.1");
confs.sin_port = htons(65460);
if(serveur=socket(AF_INET,SOCK_STREAM,0)!=-1)
{
printf("fonction socket() ok\n");
if(bind(serveur,(sockaddr *) &confs,sizeof(confs))!=-1)
{
printf("fonction bind() ok\n");
if(listen(serveur,2)!=-1)
{
printf("fonction listen() ok\n");
int ap=sizeof(confc);
if(client=accept(serveur,(sockaddr*)&confc,&ap)!=-1)
{
printf("fonctionaccept() ok\n");
}
}
}
}
return 0;
} |