aboutsummaryrefslogtreecommitdiff
path: root/works/life/computer-network-experiment/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'works/life/computer-network-experiment/client.cpp')
-rw-r--r--works/life/computer-network-experiment/client.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/works/life/computer-network-experiment/client.cpp b/works/life/computer-network-experiment/client.cpp
index aeb352f..f209171 100644
--- a/works/life/computer-network-experiment/client.cpp
+++ b/works/life/computer-network-experiment/client.cpp
@@ -8,6 +8,11 @@
#ifdef WIN32
#include <Windows.h>
#include <winsock.h>
+#else
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+
#endif
const auto connect_address = "127.0.0.1"; // control connect address
@@ -16,7 +21,7 @@ const u_short port = 1234; // control connect port
int Main() {
int client_socket;
- if ((client_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
+ if ((client_socket = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
PrintErrorMessageAndExit(CRUT("Failed to create socket!\n"));
}
@@ -28,7 +33,7 @@ int Main() {
memset(&(server_address.sin_zero), 0, sizeof(server_address.sin_zero));
if (connect(client_socket, (sockaddr *)&server_address, sizeof(sockaddr)) ==
- SOCKET_ERROR) {
+ -1) {
PrintErrorMessageAndExit(CRUT("Failed to connect!"));
}
@@ -45,6 +50,6 @@ int Main() {
SendOutput(CRUT("Received message:\n"));
- closesocket(client_socket);
+ Close(client_socket);
return 0;
}