What syscalls does a TCP server need?

The minimal useful TCP server must at least use the commands socket/bind/listen/accept/recv/send/close:

  1. tcp_listen_fd = socket(TCP): “OS, please create a TCP socket, and give me a file descriptor referencing it”.
  2. bind(tcp_listen_fd, 9999): “OS, please point TCP port 9999 to the new TCP socket”.
  3. listen(tcp_listen_fd): “OS, please start listening on the TCP port (9999)”.
  4. tcp_conn_fd = accept(tcp_listen_fd): “OS, please put me to sleep until there’s a connection to the TCP port, then give me a file descriptor referencing the new TCP connection”.
  5. bytes = recv(tcp_conn_fd): “OS, please put me to sleep until there are some bytes sent by the other end of the TCP connection, then give me some of those bytes”.
  6. send(tcp_conn_fd, bytes): “OS, please send these bytes to the other end of the TCP connection”.
  7. close(tcp_conn_fd): “OS, I’m done with this TCP connection. Close it and remove this file descriptor”.
  8. close(tcp_listen_fd): “OS, I’m done listening for new TCP connections. Stop listening on the TCP port, and remove this file descriptor”.
I just released Vidrio, a free app for macOS and Windows to make your screen-sharing awesomely holographic. Vidrio shows your webcam video on your screen, just like a mirror. Then you just share or record your screen with Zoom, QuickTime, or any other app. Vidrio makes your presentations effortlessly engaging, showing your gestures, gazes, and expressions. #1 on Product Hunt. Available for macOS and Windows.

With Vidrio

With generic competitor

More by Jim

Tagged . All content copyright James Fisher 2016. This post is not associated with my employer. Found an error? Edit this page.