Network Basics: Ports

Ports

  • In order to receive a connection, a socket must be bound to a port (by the server).
  • A port is a number in the range 0-65535 that's managed by the OS.
  • Used to identify a particular network service (or listener).
  • Ports 0-1023 are reserved by the system and used for common protocols
     FTP            Port 20
     Telnet         Port 23
     SMTP (Mail)    Port 25
     HTTP (WWW)     Port 80 
  • Ports above 1024 are reserved for user processes.

Socket programming in a nutshell

  • Server creates a socket, binds it to some well-known port number, and starts listening.
  • Client creates a socket and tries to connect it to the server (through the above port).
  • Server-client exchange some data.
  • Close the connection (of course the server continues to listen for more clients).
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 85
July 17, 2000, beazley@cs.uchicago.edu
>>>