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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
#include<stdio.h>
#include<winsock2.h>
#include<iostream>
#include <iomanip>
#include <conio.h>
#include <time.h>
using namespace std;
#pragma comment(lib,"ws2_32.lib")
#define N 1000
void AfficherUn( int * tab , int n )
{
cout <<endl ;
for ( int i = 0 ; i < n ; i++ )
{
cout <<setw(7)<< tab[i];
}
}
void Afficher ( int * tab , int nb, char M )
{
cout << endl;
cout << " Affichage du vecteur " << M << " \n " ;
for ( int i = 0 ; i < nb ; i++ )
{
cout << " V[" << setw(2) << i << "] " ;
}
AfficherUn (tab, nb) ;
cout <<endl ;
}
int Combinaison(int * & tab)
{
int nb=4;
const int max=10, min=0;
tab=new int[nb];
for(int i=0;i<nb;i++)
{
tab[i]=(rand()%(max-min+1));
}
return nb;
}
void main()
{
WSADATA wsa;
WSAStartup(MAKEWORD(2,0),&wsa); //initialisation de la socket
SOCKET server; // les socket sont associées a une ip et un num de port
SOCKET sock;
SOCKADDR_IN sinserv; // on cree une struc du type sockaddr
SOCKADDR_IN sin;
int port=1100;
//initialisation et saisi des informations
cout<<"Port : "<<port<<endl;
//cin>>port;
sinserv.sin_family=AF_INET;
sinserv.sin_addr.s_addr=INADDR_ANY;
sinserv.sin_port=htons(port);
//creation de la socket
server=socket(AF_INET,SOCK_STREAM,0);
//la socket est configuré pour écouter l'adresse et le port saisi
bind(server,(SOCKADDR*)&sinserv,sizeof(sinserv));
const int M=1000;
//pas de file d'attente
char buffer[N];
char essai[M]= "Rouge , Vert , Bleu";
listen(server,0);
int sinsize;
int err=0;
bool A = true;
while(1)
{
sinsize=sizeof(sin);
//acceptation ou non des appels
if((sock=accept(server,(SOCKADDR*)&sin,&sinsize))!=INVALID_SOCKET)
{
cout <<"connection Aziz" << endl;
while(err>-1)
{
if(A==true)
{
memset(buffer,0,sizeof(buffer));
cin.getline((char*)buffer, N);
err=send(sock,buffer,sizeof(buffer),0);
A=false;
}
else
{
recv(sock,buffer,sizeof(buffer),0);
cout<<buffer;
cout<<endl;
A=true;
}
}
}
}
} |
Partager