Socket Programming: An Introduction to Sockets and Their Operations, Study notes of Communication

An introduction to sockets, their role in inter-process communication, and various operations on sockets. It also covers the difference between blocking and non-blocking sockets, the client-server model, and well-known ports. based on a university lecture given by Vishal Shrivastav at Cornell University during CS 4450 in Spring 2018.

Typology: Study notes

2021/2022

Uploaded on 09/27/2022

wualter
wualter 🇺🇸

4.8

(96)

287 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Introduction*to*Socket*Programming
CS*4450*(Spring*2018)*
Vishal*Shrivastav,*Cornell*University
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Socket Programming: An Introduction to Sockets and Their Operations and more Study notes Communication in PDF only on Docsity!

Introduction to Socket Programming

CS 4450 (Spring 2018)

Vishal Shrivastav, Cornell University

What is a Socket?

  • A socket is a method for accomplishing inter-process

communication (IPC)

▪ Allows one process to communicate with another process on the
same or different machine

2 P1 P Socket-1 Socket- P Socket- P Socket- Network

Where does Socket fit in the Network Stack? Application Transport Network Data Link Physical Send buffer Receive buffer

Userspace
Kernel
NIC

write() read() SOCKET open() (^) close()

Blocking and Non-blocking Sockets

  • By default read() and write() operations are blocking
    • Function does not return until the operation is complete
  • read() blocks until there is some data available in the

receive buffer

  • When does write() block?
    • When the send buffer is full

Client-Server Model SERVER CLIENT 1^ CLIENT 2 CLIENT 3^ CLIENT 4 23.45.67.12 46.41.57. 93.35.17.14 53.35.17. 123.20.20. 1 2 1 2 1 2 1 2 1 2 3004 3005 3010 3004 3005 3204 3004 3028 80 22 Well known ports that clients connect to Port numbers assigned by OS

D: 123.20.20.10: S: 93.35.17.14: D: 93.35.17.14: S: 123.20.20.10:

Two traditional modes of communication

  • Connection-oriented Communication
    • Establish a logical or physical connection before exchanging data
  • Connectionless Communication
    • Start exchanging data without any prior arrangements between
endpoints

Handshake Data exchange

Client-Server Model - APIs

  • Connectionless protocol (UDP-suite) socket() bind() read() write() socket() write() read() SERVER CLIENT

Stream vs Datagram

  • Stream based protocols (such as TCP) work on bytes granularity
  • When to stop reading? write(12 bytes) read(2 bytes) read(6 bytes) read(4 bytes) Receive buffer

Questions?

Demos