SOCKET(1)

πŸ’– SOCKET(1) πŸ’–

okay bestie, welcome to socket, from the General Commands Manual section 1 (that's user commands, iykyk). this little icon is gonna make a TCP or UNIX domain socket and hook it straight up to your stdin and stdout. slay.


✨ NAME ✨

socket β€” create a TCP or a UNIX domain socket and connect to stdin/out


🌸 SYNOPSIS 🌸

socket [ -bcfqrvw ] [ -p command ] [ -B local address ] host port
socket [ -bcfqrvw ] [ -p command ] /path
socket [ -bcfqrvw ] [ -p command ] [ -B local address ] -s [ -l ] port
socket [ -bcfqrvw ] [ -p command ] -s [ -l ] /path

πŸ¦‹ DESCRIPTION πŸ¦‹

so socket creates an Internet domain TCP socket or a UNIX domain stream socket, and then connects it to stdin and stdout. literally just wires it right up. πŸ’…

the host argument can be an Internet number in dot-notation (like 130.149.28.10) or a domain name. if it's a domain name, it has to be resolvable to a valid Internet address with gethostbyname(3) β€” no cap, that's a requirement. 🫢

the port argument can be a port number, or a service name that getservbyname(3) can map to a port number.

if you want a UNIX domain socket instead of an Internet socket, you just specify the path instead of an internet host (canonical domain named or dot-notated, either one). the hostname gets treated as a pathname if it contains at least a single slash β€” at least one slash, that's the vibe check. so if you wanna create or connect to a socket in the current directory, use ./filename to specify the connection point. periodt. πŸ’–


✨ OPTIONS ✨

  • -b (background) β€” the program forks itself into the background, detaches from its controlling tty, closes the file descriptors associated with the tty, and changes its current directory to the root directory. bye bestie, going ghost mode πŸ‘»
  • -B (local address) β€” this option specifies which local address to binded to when making a connection. (yes, the manpage really says "binded", we don't fix that, we respect the source πŸ’€)
  • -c (crlf) β€” Linefeed characters (LF) are converted to a Carriage Return Linefeed sequence (CRLF) when written to the socket. CRLF sequences read from the socket are converted to a single LF. it's giving translator energy 🧚
  • -f (fork) β€” when a server connection has been accepted, a separate process is forked to handle the connection in background. multitasking queen πŸ‘‘
  • -l (loop) β€” (only valid with -s) after a connection has been closed, another connection is accepted. it never stops, iconic behavior ✨
  • -p (program) β€” the specified command is executed for each connection. its standard input, standard output, and standard error channels are connected to the socket. command can be any shell command since it is passed to /bin/sh. 🐚
  • -q (quit) β€” the connection is closed when an end-of-file condition occurs on standard input. when stdin says "i'm done", we listen πŸ™ˆ
  • -r (read only) β€” no data is read from standard input and written to the socket. we're just here to receive, lowkey 🌸
  • -s (server) β€” a server socket is created. a hostname argument is not required of Internet sockets, only the port number β€” but a pathname is required for UNIX domain sockets. πŸŽ€
  • -v (verbose) β€” messages about connections etc. are issued to stderr. it will tell you everything, main character energy fr fr πŸ—£οΈ
  • -w (write only) β€” no data is read from the socket and written to the standard output. talk only, no listening πŸ’…
  • -version β€” socket prints its version ID and terminates. this must be the first argument to have an effect β€” put it anywhere else and it just does nothing, so don't play yourself ⭐

🌈 EXAMPLES 🌈

the command

socket -v coma.cs.tu-berlin.de nntp

connects to the nntp port (port 119) of coma.cs.tu-berlin.de (130.149.28.10). πŸ”₯

the command

socket -sl 3425

creates a server socket on port 3425 on the local host and waits for a connection. after a connection has been closed, a new connection is accepted. πŸ’–

the command

socket -wslqvp "echo Socket! " 1938

creates a server socket on port 1938 on the local host and waits for a connection. when a connection is accepted, the string "Socket!" is written to the socket. no data is read from the socket and written to the finger program. the connection is closed when an end-of-file condition at the standard output of the program occurs. then a new connection is accepted. πŸ¦‹


πŸ’€ DIAGNOSTICS πŸ’€

lots of diagnostics for failed system calls. (yes. "lots." that's the whole description. we love a vague queen.)

  • unknown host host β€” host's address could not be resolved. 😭
  • Signal signal caught, exiting β€” socket exits on any signal other than SIGTSTP, SIGCONT, SIGCLD, SIGQUIT. those four it tolerates, everything else is bye bye 🫢

a non-zero exit code is returned if socket terminates due to an error condition or a signal.


πŸ‘‘ SEE ALSO πŸ‘‘

ip(7), tcp(7), unix(7), accept(2), bind(2), listen(2), connect(2), socket(2), gethostbyname(3), getservbyname(3)


πŸ™ˆ BUGS πŸ™ˆ

  • socket -p terminates due to a SIGPIPE signal when there is more data from the socket available than the executed program wants to read. so if the program is a picky eater, everything explodes. not cute. πŸ’€
  • please report any other bugs to the author.

⭐ VERSION ⭐

this manual page describes Socket-1.1.


πŸŽ€ AUTHOR πŸŽ€

Juergen Nickelsen <nickel@cs.tu-berlin.de>


and that's the whole page bestie!! written Aug 6, 1992 (a whole legend, ancient and still iconic), from the General Commands Manual, version SOCKET(1). go make some sockets, you got this πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from