|
Sponge
CS144's user-space TCP library
|
Go to the documentation of this file.
10 cerr <<
"Usage: " << argv0 <<
" [-l] <host> <port>\n\n"
11 <<
" -l specifies listen mode; <host>:<port> is the listening address." <<
endl;
14 int main(
int argc,
char **argv) {
16 bool server_mode =
false;
17 if (argc < 3 || ((server_mode = (
strncmp(
"-l", argv[1], 3) == 0)) && argc < 4)) {
27 listening_socket.
bind({argv[2], argv[3]});
29 return listening_socket.
accept();
32 connecting_socket.
connect({argv[1], argv[2]});
33 return connecting_socket;
TCPSocket accept()
Accept a new incoming connection.
A wrapper around TCP sockets.
void bind(const Address &address)
Bind a socket to a specified address with bind(2), usually for listen/accept.
void listen(const int backlog=16)
Mark a socket as listening for incoming connections.
void show_usage(const char *argv0)
void connect(const Address &address)
Connect a socket to a specified peer address with connect(2).
void bidirectional_stream_copy(Socket &socket)
Copy socket input/output to stdin/stdout until finished.
void set_reuseaddr()
Allow local address to be reused sooner via SO_REUSEADDR.
int main(int argc, char **argv)