Skip to content

Instantly share code, notes, and snippets.

@Rapptz
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rapptz/2ced78d4201b20f76b91 to your computer and use it in GitHub Desktop.
Save Rapptz/2ced78d4201b20f76b91 to your computer and use it in GitHub Desktop.
Sockets.
#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);
}
#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");
}
(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