diff options
author | crupest <crupest@outlook.com> | 2021-06-06 23:43:52 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-06-06 23:43:52 +0800 |
commit | 800923717d1f95cd16b270ad8f1e430f77f33f57 (patch) | |
tree | a6370a2a6f1393ba88f25392a702d291dec8a73b /computer-network-experiment/client.cpp | |
parent | a6088689ec605c97b846fb52beadc0de89fccf76 (diff) | |
download | life-800923717d1f95cd16b270ad8f1e430f77f33f57.tar.gz life-800923717d1f95cd16b270ad8f1e430f77f33f57.tar.bz2 life-800923717d1f95cd16b270ad8f1e430f77f33f57.zip |
...
Diffstat (limited to 'computer-network-experiment/client.cpp')
-rw-r--r-- | computer-network-experiment/client.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/computer-network-experiment/client.cpp b/computer-network-experiment/client.cpp index aeb352f..f209171 100644 --- a/computer-network-experiment/client.cpp +++ b/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;
}
|