Sockets
Sockets
Review of networks
We want to enable bidirectional communication between server /client
Ports are assigned for each program to use to communicate
This is needed to allow different computers to communicate.
Issues that don’t occur on single computers can arise in network settings.
server
client
Address: 127.0.0.1
Address: 142.126.229.171
Port
49512
Stream Sockets
Sockets are file descriptors that are created to allow servers and clients to communicate.
They are created similarly (in spirit) to pipes but
Are bi-directional
Need to be bound to addresses to allow external computers to find them
Protocols need to be specified so that machine specific differences don’t cause problems.
Write / read works exactly like pipes or files in Linux.
Guarantees all messages are received and in order
Delivery time not guaranteed.
Must be careful that read does not guarantee that each packet is fully delivered during read.
Layout of Stream socket calls
Socket: Creates a passive or active socket
Bind: Sets address of the socket
Not needed on client end
Listen: allows socket to accept
connections from other sockets.
Accept: blocks and waits for a connection
After connection communication proceeds as
normal
Connect: Initiates connection with server
from client side.
Commands
Domain: AF_INET (sets protocol family)
Type: SOCK_STREAM (sets stream socket TCP protocol)
Protocol: 0 (only 1 protocol)
Commands
addr is a struct, for the particular struct we will use sockaddr_in we need to recast to *const struct sockaddr.
Addrlen-> size of address type
Commands
Backlog: maximum number of pending connections that socket can store.
Commands
/docProps/thumbnail.jpeg