CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
gen_udp and gen_tcp in Elixir
1. gen_udp/tcp and data streaming
github.com/stepnivlk
---
Streetbees
(we’re hiring)
2. Why should I even care about gen_*?
● Relatively low-level interface to udp/tcp sockets
● We can control how messages are received
● Socket can be reconfigured on the fly
● Useful when we need to stream binary data to clients
We may need to define chunks of data being sent,
control when we send those chunks
or handle interrupts (my use case - mp3 streaming)
● Allows us to understand how various libraries
work ‘behind curtains’
4. UDP
● Stateless / No session
● Broken into packets
● Untagged
● No order guarantee
● No ‘receive’ guarantee
5. TCP
● Stateful, connection-based
● Handshake before data sending
● Tagged packets
● Order guarantee
● Receive guarantee
● Multiple communications over
single port
Client
Server
14. (5/9) Wait, what is that <<”quit”, _::binary>>?
The ID3v2 tag size is encoded with four bytes where the most significant
bit (bit 7) is set to zero in every byte, making a total of 28 bits.
19. ● Can only handle requests coming one-by-one
● Sequential flow - acceptor sets itself up, then spawns new process
NaiveTcp
20. ● More parallel - pool of processes ready to accept client
● We need supervisor with many acceptor workers
● Supervisor passes listen socket to each worker
BetterTcp
28. Ok, what about something real?
Meet my radio project [massive WIP]
● Shoutcast compatible mp3 streaming server
● Each listener has own process and identity
● Based on preferences server picks songs for user and serves it to them
● Underground spotify (think radio23.cz + ektoplazm.com)