Hi, I find sockets quite interesting and since I just have started to learn a little about them i'm not a pro
(that won't be a secret to anyone who see my code.)
What I want to know is, if there's alot difference between unix socket programming and winsock.
Here's my unix code for a server program which does nothing except telling you when an incoming connection is accepted.
Any coments on the code is very welcome, I would really appreciate
int serv, clnt, port, sin_size = sizeof(sockaddr_in);
sockaddr_in server, client;
bool loop = true;
cout << "Select port: "; cin >> port;
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(port);
if ((serv = socket(AF_INET, SOCK_STREAM, 0)) < 0)
cout << "An error occured while trying to create socket... quitting!";
if (bind(serv, (sockaddr*)&server, sizeof(sockaddr)) < 0)
cout << "An error occured while trying to bind socket... quitting!";
if (listen(serv, 1) < 0)
cout << "An error occured while trying to listen for a connection... quitting!";
if (clnt = accept(serv, (sockaddr*)&client, &sin_size) < 0)
cout << "Could not accept connection!";
cout << "Got connection from: " << inet_ntoa(client.sin_addr) << "!";
if (send(clnt, "Connection successfull.\n", 24, 0) > 0)
loop = false;
any corrections if there's something wrong or stupid about the code.
Most importantly I would really really appreciate a good link for a winsock tutorial.