aboutsummaryrefslogtreecommitdiff
path: root/works/life/computer-network-experiment/client.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-06-06 23:43:52 +0800
committercrupest <crupest@outlook.com>2021-06-06 23:43:52 +0800
commit7a269e185fc59e5f81e7c91e6e75891ba2ca4b3b (patch)
tree8a0baf8e5eac69003770306e7968c1196a5a49dd /works/life/computer-network-experiment/client.cpp
parentfcd2304e04dd3fabdefce4293b1b76ad99f8ed73 (diff)
downloadcrupest-7a269e185fc59e5f81e7c91e6e75891ba2ca4b3b.tar.gz
crupest-7a269e185fc59e5f81e7c91e6e75891ba2ca4b3b.tar.bz2
crupest-7a269e185fc59e5f81e7c91e6e75891ba2ca4b3b.zip
import(life): ...
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;
}