-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKRSSGCountClient.cpp
43 lines (40 loc) · 1.14 KB
/
KRSSGCountClient.cpp
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
#include <iostream>
#include <WS2tcpip.h>
#pragma comment(lib, "ws2_32.lib")
using namespace std;
int main() {
// Initialize Winsock
WSADATA wsData;
WORD ver = MAKEWORD(2, 2);
int wsOk = WSAStartup(ver, &wsData);
if (wsOk != 0) {
cerr << "Can't initialize Winsock! Quitting" << endl;
return 1;
}
// Create a socket
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET) {
cerr << "Can't create socket! Quitting" << endl;
return 1;
}
// Connect to the server
sockaddr_in srv;
srv.sin_family = AF_INET;
srv.sin_port = htons(9000);
inet_pton(AF_INET, "127.0.0.1", &srv.sin_addr);
int conn = connect(sock, (sockaddr*)&srv, sizeof(srv));
if (conn == SOCKET_ERROR) {
cerr << "Can't connect to server! Quitting" << endl;
closesocket(sock);
WSACleanup();
return 1;
}
int counter = 1;
send(sock, (char*)&counter, sizeof(counter), 0);
//asking user for input
cout << "Enter the number of prisoners to connect: " << endl;
int n;
cin >> n;
send(sock, (char*)&n, sizeof(n), 0);
return 0;
}