Computer Communication Networks Socket Programming

Similar documents
Chapter II: Application Layer

Application Programming Interfaces

We will cover in this order: 2.1, 2.7, 2.5, 2.4, 2.2

Chapter 2: outline. 2.1 principles of network applications. 2.6 P2P applications 2.7 socket programming with UDP and TCP

Chapter 2: outline. 2.6 P2P applications 2.7 socket programming with UDP and TCP

Client/Server Computing & Socket Programming

CMPE 150/L : Introduction to Computer Networks. Chen Qian Computer Engineering UCSC Baskin Engineering Lecture 6

Distributed Systems. Remote Procedure Calls

Distributed Systems. Networking Slides courtesy Kurose & Ross

Quick Guide to Python Socket Programming 吳俊興 國立高雄大學資訊工程學系

The Application Layer: Sockets Wrap-Up

Communication in Distributed Systems: Sockets Programming. Operating Systems

Chapter 2: outline. 2.1 principles of network applications app architectures app requirements

Application Layer. CMPS 4750/6750: Computer Networks

Chapter 2 Application Layer

Computer Communication Networks Foundation

JAVA SOCKET PROGRAMMING

Chapter 2: Application Layer. Chapter 2: application layer. outline. Some network apps. Client-server architecture. Application architectures

Network Programming with Python. Sébastien Tixeuil

Esempi di programmi client/server in Python 2

Chapter 2 outline. 2.1 Principles of app layer protocols

Chapter 2 Application Layer

Web Caching and HTTPS

Chapter 2: outline. 2.5 P2P applications 2.6 video streaming and content distribution networks 2.7 socket programming with UDP and TCP

Chapter 2: outline. 2.5 P2P applications 2.6 video streaming and content distribution networks 2.7 socket programming with UDP and TCP

CSCD 330 Network Programming Spring 2018

CSC 401 Data and Computer Communications Networks

Chapter 2 Application Layer

Computer Networking Introduction

CS 355. Computer Networking. Wei Lu, Ph.D., P.Eng.

Chapter 2 Application Layer

Chapter 2 Application Layer

EC441 Fall 2018 Introduction to Computer Networking Chapter 2: Application Layer

Application Layer. Chapter 2. Computer Networking: A Top Down Approach. A note on the use of these Powerpoint slides:

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Chapter 2 Application Layer

IEMS 5780 / IERG 4080 Building and Deploying Scalable Machine Learning Services

Πρωτόκολλα Διαδικτύου (ΨΣ-326 DS151)

Client/Server Computing & Socket Programming

Chapter 2 Application Layer

Chapter 2 Application Layer

Chapter 2 Application Layer

Java Network Programming

CSCD 330 Network Programming Spring 2018

Network Programming in Python. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Chapter 2 Application Layer

Chapter 2: outline. 2.6 P2P applications 2.7 socket programming with UDP and TCP

CSCD 330 Network Programming Winter 2019

COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC)

Transport Layer (TCP/UDP)

Introduction to Sockets 9/25/14

Foundations of Telematics

TRANSMISSION CONTROL PROTOCOL. ETI 2506 TELECOMMUNICATION SYSTEMS Monday, 7 November 2016

Chapter 2 Application Layer. Lecture 4: principles of network applications. Computer Networking: A Top Down Approach

CPSC 441 UDP Socket Programming. Department of Computer Science University of Calgary

Lecture 05: Application Layer (Part 02) FTP, Peer-to-Peer, . Dr. Anis Koubaa

CS 3516: Advanced Computer Networks

Layer 4 - Transport Layer. What do we need a Transport Layer for? Transport Protocols in the TCP/IP Reference Model. The Transport Layer TCP and UDP

System Programming. Introduction to computer networks

Introduction to the Application Layer. Computer Networks Term B14

Network Programming. Introduction to Sockets. Dr. Thaier Hayajneh. Process Layer. Network Layer. Berkeley API

CC451 Computer Networks

Interprocess Communication Mechanisms

shared storage These mechanisms have already been covered. examples: shared virtual memory message based signals

Goal and A sample Network App

Transport layer Internet layer

Layer 4 - Transport Layer

Different Layers Lecture 21

ECE 4450:427/527 - Computer Networks Spring 2017

FTP. Mail. File Transfer Protocol (FTP) FTP commands, responses. Electronic Mail. TDTS06: Computer Networks

9th Slide Set Computer Networks

Lab 2 Solution. Jon Turner. CSE 473 Introduction to Computer Networks. (20 points) Place a copy of your source code for TcpMapServer here.

CMPE 150/L : Introduction to Computer Networks. Chen Qian Computer Engineering UCSC Baskin Engineering Lecture 4

ECE 650 Systems Programming & Engineering. Spring 2018

Review of Previous Lecture

CSC 4900 Computer Networks: P2P and Sockets

4. The transport layer

Memory-Mapped Files. generic interface: vaddr mmap(file descriptor,fileoffset,length) munmap(vaddr,length)

Configure Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) Service Settings on a Switch

CSC 4900 Computer Networks: End-to-End Design

Chapter 2. Application Layer. Chapter 2: Application Layer. Application layer - Overview. Some network apps. Creating a network appication

CMSC 322 Computer Networks Applications and End-To- End

SOCKET. Valerio Di Valerio

transmission media and network topologies client/server architecture layers, protocols, and sockets

CSEN 503 Introduction to Communication Networks. Mervat AbuElkheir Hana Medhat Ayman Dayf. ** Slides are attributed to J. F.

Esempi di programmi client/server in Python 3

TSIN02 - Internetworking

Computer Systems and Networks

Lecture 11. Transport Layer (cont d) Transport Layer 1

Unix Network Programming

Networking. Chapter How to identify machines on internet Ports

Processes communicating. Network Communication. Sockets. Addressing processes 4/15/2013

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication

Transport Layer. Gursharan Singh Tatla. Upendra Sharma. 1

Network Communication

Protocol Layers, Security Sec: Application Layer: Sec 2.1 Prof Lina Battestilli Fall 2017

Networking and Security

QUIZ: Longest Matching Prefix

Tommy Färnqvist, IDA, Linköping University

Chapter 1 Introduction

Transcription:

Computer Communication Networks Socket Programming ICEN/ICSI 416 Fall 2018 Prof. Aveek Dutta 1

Application Programming Interface Interface exported by the network Since most network protocols are implemented (those in the high protocol stack) in software and nearly all computer systems implement their network protocols as part of the operating system, when we refer to the interface exported by the network, we are generally referring to the interface that the OS provides to its networking subsystem The interface is called the network Application Programming Interface (API) 2

Application Programming Interface (Sockets) Socket Interface was originally provided by the Berkeley distribution of Unix Now supported in virtually all operating systems Each protocol provides a certain set of services, and the API provides a syntax by which those services can be invoked in this particular OS 3

Socket What is a socket? The point where a local application process attaches to the network An interface between an application and the network An application creates the socket The interface defines operations for Creating a socket Attaching a socket to the network Sending and receiving messages through the socket Closing the socket 4

Sockets process sends/receives messages to/from its socket socket analogous to door between application process & end-end-transport sending process shoves message out door sending process relies on transport infrastructure on other side of door to deliver message to socket at receiving process application process socket application process controlled by app developer transport network link physical Internet transport network link physical controlled by OS 5

Socket programming Two socket types for two transport services: User Datagram Protocol (UDP): o unreliable datagram Transmission Control Protocol (TCP): o reliable, byte stream-oriented Application Example: 1. client reads a line of characters (data) from its keyboard and sends data to server 2. server receives the data and converts characters to uppercase 3. server sends modified data to client 4. client receives modified data and displays line on its screen 6

Socket programming with UDP UDP: no connection between client & server no handshaking before sending data sender explicitly attaches IP destination address and port # to each packet receiver extracts sender IP address and port# from received packet UDP: transmitted data may be lost or received out-of-order Application viewpoint: UDP provides unreliable transfer of groups of bytes ( datagrams ) between client and server 7

Port Numbers Commonly used: 21: File Transfer Protocol (FTP) 22: Secure Shell (SSH) 23: Telnet remote login service 25: Simple Mail Transfer Protocol (SMTP) 80: Hypertext Transfer Protocol (HTTP) used in the World Wide Web 110: Post Office Protocol (POP3) 123: Network Time Protocol (NTP) 143: Internet Message Access Protocol (IMAP) 443: HTTP Secure (HTTPS) The registered ports are those from 1024 through 49151. IANA maintains the official list of registered ports. The dynamic or private ports are those from 49152 through 65535. 8

Client/server socket interaction: UDP server (running on serverip) create socket, port= x: serversocket = socket(af_inet,sock_dgram) read datagram from serversocket write reply to serversocket specifying client address, port number client create socket: clientsocket = socket(af_inet,sock_dgram) Create datagram with server IP and port=x; send datagram via clientsocket read datagram from clientsocket close clientsocket 9

Socket programming with TCP client must contact server server process must first be running server must have created socket (door) that welcomes client s contact client contacts server by: Creating TCP socket, specifying IP address, port number of server process when client creates socket: client TCP establishes connection to server TCP when contacted by client, server TCP creates new socket for server process to communicate with that particular client allows server to talk with multiple clients source port numbers used to distinguish clients (more in Chap 3) application viewpoint: TCP provides reliable, in-order byte-stream transfer ( pipe ) between client and server 10

Client/server socket interaction: TCP server (running on hostid) client create socket, port=x, for incoming request: serversocket = socket() wait for incoming connection request connectionsocket = serversocket.accept() read request from connectionsocket write reply to connectionsocket close connectionsocket TCP connection setup create socket, connect to hostid, port=x clientsocket = socket() send request using clientsocket read reply from clientsocket close clientsocket 11

Socket Programming in C http://beej.us/guide/bgnet/ 12

C Program Output UDP Server TCP Server UDP Client TCP Client 13

Socket Programming in Python https://docs.python.org/2/howto/sockets.html 14

Example app: UDP client include Python s socket library create UDP socket for server get user keyboard input Attach server name, port to message; send into socket read reply characters from socket into string print out received string and close socket Python UDPClient from socket import * servername = hostname serverport = 12000 clientsocket = socket(af_inet, SOCK_DGRAM) message = raw_input( Input lowercase sentence: ) clientsocket.sendto(message.encode(), (servername, serverport)) modifiedmessage, serveraddress = clientsocket.recvfrom(2048) print modifiedmessage.decode() clientsocket.close() 15

Example app: UDP server create UDP socket bind socket to local port number 12000 loop forever Read from UDP socket into message, getting client s address (client IP and port) send upper case string back to this client Python UDPServer from socket import * serverport = 12000 serversocket = socket(af_inet, SOCK_DGRAM) serversocket.bind(('', serverport)) print ( The server is ready to receive ) while True: message, clientaddress = serversocket.recvfrom(2048) modifiedmessage = message.decode().upper() serversocket.sendto(modifiedmessage.encode(), clientaddress) 16

Example app: TCP client create TCP socket for server, remote port 12000 No need to attach server name, port Python TCPClient from socket import * servername = servername serverport = 12000 clientsocket = socket(af_inet, SOCK_STREAM) clientsocket.connect((servername,serverport)) sentence = raw_input( Input lowercase sentence: ) clientsocket.send(sentence.encode()) modifiedsentence = clientsocket.recv(1024) print ( From Server:, modifiedsentence.decode()) clientsocket.close() 17

Example app: TCP server create TCP welcoming socket server begins listening for incoming TCP requests loop forever server waits on accept() for incoming requests, new socket created on return read bytes from socket (but not address as in UDP) close connection to this client (but not welcoming socket) Python TCPServer from socket import * serverport = 12000 serversocket = socket(af_inet,sock_stream) serversocket.bind((,serverport)) serversocket.listen(1) print The server is ready to receive while True: connectionsocket, addr = serversocket.accept() sentence = connectionsocket.recv(1024).decode() capitalizedsentence = sentence.upper() connectionsocket.send(capitalizedsentence. encode()) connectionsocket.close() 18