Last active
August 29, 2015 14:15
-
-
Save Rapptz/2ced78d4201b20f76b91 to your computer and use it in GitHub Desktop.
Sockets.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <net/socket.hpp> | |
#include <iostream> | |
int main() { | |
net::socket client(net::socket::ipv4, net::socket::stream); | |
client.connect("127.0.0.1", 3667); | |
std::cout << client.receive(16); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <net/socket.hpp> | |
#include <iostream> | |
int main() { | |
net::socket server(net::socket::ipv4, net::socket::stream); | |
unsigned port = 3667; | |
server.bind("127.0.0.1", port); | |
server.listen(port); | |
std::cout << "Waiting for a client..\n"; | |
auto client = server.accept(); | |
std::cout << "Client connected\n"; | |
client.send("Hello World!\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(tab one) | |
λ server | |
Waiting for a client.. | |
Client connected | |
(tab two) | |
λ client | |
Hello World! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment