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
|
#include <winsock2.h>
#include <windows.h>
#include <iostream>
bool Insocket(long PORT)
{
WSADATA WSAData;
WSAStartup(MAKEWORD(2,0), &WSAData);
SOCKET sock;
SOCKET csock;
SOCKET cs;
SOCKADDR_IN sin;
SOCKADDR_IN csin;
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_family = AF_INET;
sin.sin_port = htons(PORT);
bind(sock, (SOCKADDR *)&sin, sizeof(sin));
listen(sock, 0);
char *msg=new char[1];
while(1)
{
int sinsize = sizeof(csin);
cs=accept(sock,NULL,NULL);
if (cs!=INVALID_SOCKET){
printf("Connection=>\n");
send(cs, "", 1, 0);//Pour que les lettre saffiche sur telnet
while ((recv(cs,&msg,1,0))){//atten un message
printf("%c",msg[0]);//affiche
}
}
}
}
int main()
{
Insocket(23);
} |
Partager