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
| #define P
#include<QApplication>
#include<QWidget>
#include<QPushButton>
#include <QTextEdit>
#include <QString>
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include"ap.h"
using namespace std;
int main(int argc, char **argv)
{
QApplication app(argc,argv);
QWidget fenetre;
fenetre.resize(800,600);
QPushButton boutonjer("jer",&fenetre);
QPushButton boutonseb("Seb",&fenetre);
QPushButton boutonthi("thi",&fenetre);
cliquejer ac;
cliquethi ac2;
QPushButton boutonsend("envoyer",&fenetre);
QTextEdit bddr(" ",&fenetre);
QTextEdit bdds("Taper ici votre message a envoyer",&fenetre);
boutonjer.setGeometry(10, 10,50,30);
boutonseb.setGeometry(375, 10,50,30);
boutonthi.setGeometry(740, 10,50,30);
boutonsend.setGeometry(370, 500,75,45);
bddr.setGeometry(12, 52,775,190);
bdds.setGeometry(12, 280,775,190);
fenetre.show();
QPushButton::connect(&boutonjer,SIGNAL(clicked()),&ac,SLOT(AfficheConnect()));
QPushButton::connect(&boutonthi,SIGNAL(clicked()),&ac2,SLOT(AfficheConnect()));
/**serveur*/
WSADATA WSAData;
WSAStartup(MAKEWORD(2,0), &WSAData);
SOCKET sock;
SOCKADDR_IN sin;
SOCKET sockbis;
SOCKADDR_IN sinbis;
char buffer[200];
int val=1;
int valb=1;
sock=socket(AF_INET,SOCK_STREAM,0);
if(sock !=-1)
{
sin.sin_addr.s_addr = htonl (INADDR_ANY);
sin.sin_family = AF_INET;
sin.sin_port = htons (8080);
if(bind(sock,(SOCKADDR *)&sin, sizeof(sin)) != -1)
{
if(listen(sock,3) != SOCKET_ERROR)
{
printf("Attente d'une connexion...\n");
while(val)
{
int sinsize = sizeof(sinbis);
sockbis=accept(sock,(SOCKADDR *)&sinbis,&sinsize);
if(sockbis != SOCKET_ERROR)
{
printf("Connexion etablie\n\n\n\n");
val=0;
while(valb)
{
if(recv(sockbis,buffer,sizeof(buffer),0) != SOCKET_ERROR)
{
printf("%s\n",buffer);
}
}
}
}
}
}
}
closesocket(sock);
closesocket(sockbis);
WSACleanup( );
/***/
return app.exec();
} |
Partager