generated from sigonasr2/CPlusPlusProjectTemplate
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>master
parent
63440c5996
commit
b7691a230e
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
@ -0,0 +1,31 @@ |
||||
#include "pixelGameEngine.h" |
||||
#include "sys/socket.h" |
||||
#include "netinet/in.h" |
||||
#include <unistd.h> |
||||
#include <arpa/inet.h> |
||||
|
||||
using namespace std; |
||||
|
||||
void runSocket() { |
||||
cout << "Connecting."; |
||||
int sock = socket(AF_INET,SOCK_STREAM,0); |
||||
if (sock<0) { |
||||
cout << "Socket connection error."; |
||||
} |
||||
struct sockaddr_in addr; |
||||
addr.sin_family=AF_INET; |
||||
addr.sin_port=htons(8080); |
||||
if (inet_pton(AF_INET, "192.168.1.85", &addr.sin_addr)<=0) { |
||||
cout << "Invalid address"; |
||||
} |
||||
int client_fd = connect(sock,(struct sockaddr*)&addr,sizeof(addr)); |
||||
if (client_fd<0) { |
||||
cout << "Failed to connect."; |
||||
} |
||||
send(sock,"GET / HTTP/1.1\n",strlen("GET / HTTP/1.1\n"),0); |
||||
char buffer[1024] = {}; |
||||
while (read(sock,buffer,1024)!=0) { |
||||
cout << buffer << "\n"; |
||||
} |
||||
close(client_fd); |
||||
} |
Loading…
Reference in new issue