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
|
#include <cstdlib>
#include <iostream>
#include <netinet/in.h>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
//We're creating the socket, AF_INET, SOCK_STREAM Type, 6
//stands for tcp.
int fdc, fdl = socket(AF_INET, SOCK_STREAM, 6);
//We're creating a struct from sockaddr_in
//AF_INET, custom port (15557), Ip is our loopback
struct sockaddr_in dir = { AF_INET, htons(15557), INADDR_ANY};
//Binding socket to port.
char ch;
bind(fdl, (sockaddr*) &dir, sizeof(dir));
listen(fdl, 1);
fdc = accept(fdl, NULL, NULL);
close(fdl);
while (read(fdc, &ch, 1))
write(1, &ch, 1);
cout<<"\n";
cout<<"End?";
return 0;
}
|