Skip to content

Why do stream sockets require net/read and net/write while datagram sockets require net/recv-from and net/send-to? #1441

Answered by psagers
amano-kenji asked this question in Q&A
Discussion options

You must be logged in to vote

If you're new to networking, Janet's documentation probably isn't the best place to start. I would look for a general tutorial on networking first.

Briefly, a stream socket is like a telephone call: you make a connection, both sides know who they're talking to, and you can just talk back and forth until you're done. Datagrams are more like putting postcards in the mail: you have to put the destination and return address on each one individually. Also, at least in the case of UDP, there's no guarantee that it will arrive.

Most everyday networking, such as https, is all streams. Datagrams are more niche; if you're not sure what they are, you can probably ignore them until later.

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@amano-kenji
Comment options

@psagers
Comment options

Answer selected by amano-kenji
@bakpakin
Comment options

@amano-kenji
Comment options

@psagers
Comment options

@amano-kenji
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants