BITS-Pilani Hyderabad Campus

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

Lecture 2. Outline. Layering and Protocols. Network Architecture. Layering and Protocols. Layering and Protocols. Chapter 1 - Foundation

Problem Set 4 Due: Start of class, October 5

Joseph Faber Wonderful Talking Machine (1845)

Interprocess Communication Mechanisms

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

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

What is a Network? TCP / IP. The ISO OSI Model. Protocols. The TCP/IP Protocol Suite. The TCP/IP Protocol Suite. Computer network.

Figure 1: Graphical representation of a client-server application

Distributed Internet Applications - DIA. Servers and Sockets

Application Programming Interfaces

TCP and Concurrency. The third assignment at DA

C19: User Datagram and Multicast

Transport Layer. Chapter 3: Transport Layer

Socket Programming. Sungkyunkwan University. Hyunseung Choo Copyright Networking Laboratory

Network Programming in Python. based on Chun, chapter 2; plus material on classes

Chapter 9: UDP sockets & address conversion function

Agenda. Before we start: Assignment #1. Routing in a wide area network. Protocols more concepts. Internetworking. Congestion control

Computer Communication Networks Socket Programming

CS September 2017

CCNA R&S: Introduction to Networks. Chapter 7: The Transport Layer

Transport Layer. Gursharan Singh Tatla. Upendra Sharma. 1

Programming Assignment 3

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

OSI Transport Layer. Network Fundamentals Chapter 4. Version Cisco Systems, Inc. All rights reserved. Cisco Public 1

UNIX Sockets. Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E.

CN1047 INTRODUCTION TO COMPUTER NETWORKING CHAPTER 6 OSI MODEL TRANSPORT LAYER

IT 341: Introduction to System

A Client-Server Exchange

Introduction to Sockets 9/25/14

Distributed Systems Recitation 2. Tamim Jabban

Client-Server Interaction and Network Applications

Transport protocols Introduction

( A ) 1. WAP is a (A) protocol (B) hardware (C) software (D) network architecture

QUIZ: Longest Matching Prefix

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

Chapter 7 Transport Layer. 7.0 Introduction 7.1 Transport Layer Protocols 7.2 TCP and UDP 7.3 Summary

Transport Layer (TCP/UDP)

TCP/IP protocol suite

Programming with TCP/IP. Ram Dantu

Distributed Real-Time Control Systems. Module 26 Sockets

Lecture 2-ter. 2. A communication example Managing a HTTP v1.0 connection. Managing a HTTP request. transport session. Step 1 - opening transport

Computer Networks/DV2 Lab

CSC 401 Data and Computer Communications Networks

JAVA SOCKET PROGRAMMING

Communication in Distributed Systems: Sockets Programming. Operating Systems

ECE 650 Systems Programming & Engineering. Spring 2018

DCCP (Datagram Congestion Control Protocol)

9th Slide Set Computer Networks

The OSI Model. Open Systems Interconnection (OSI). Developed by the International Organization for Standardization (ISO).

Novell TCP IP for Networking Professionals.

UDP: Datagram Transport Service

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

Server algorithms and their design

Chapter 6. The Protocol TCP/IP. Introduction to Protocols

Chapter 23 Process-to-Process Delivery: UDP, TCP, and SCTP 23.1

EECS122 Communications Networks Socket Programming. Jörn Altmann

Chapter 11. User Datagram Protocol (UDP)

CSE 461 Connections. David Wetherall

The basic server algorithm. Server algorithms and their design. Problems with the simple server? Servers. overview ofaserver

SOCKET. Valerio Di Valerio

A set of processes distributed over a network that communicate via messages. Processes communicate via services offered by the operating system

Transport Layer Overview

CSEP 561 Connections. David Wetherall

Distributed Systems. 3. Access to the Transport Layer. Werner Nutt

Data Transport over IP Networks

Development of reliable protocol Sliding window protocols. C = channel capacity in bps I = interrupt/service time + propagation delay

4.2 Virtual Circuit and Datagram Networks

CSEP 561 Connections. David Wetherall

THE TRANSPORT LAYER UNIT IV

Assignment 1: tcpbridge

User Datagram Protocol(UDP)

Practical Session #09 Exceptions & Networking. Tom Mahler

Contents: 1 Basic socket interfaces 3. 2 Servers 7. 3 Launching and Controlling Processes 9. 4 Daemonizing Command Line Programs 11

Chapter 8: I/O functions & socket options

6. The Transport Layer and protocols

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

CSCI 415 Computer Networks Homework 2 Due 02/13/08

Chapter 10 User Datagram Protocol (UDP)

Java networking using sockets

Pemrograman Jaringan Network Client

Version 2.1 User Guide 08/2003

Networking. Lecture 25 ish? COP 3252 Summer July 11, 2017

Lab 0. Yvan Petillot. Networks - Lab 0 1

Socket Programming. Omer Ozarslan

Layer 4: UDP, TCP, and others. based on Chapter 9 of CompTIA Network+ Exam Guide, 4th ed., Mike Meyers

Transport Layer. The transport layer is responsible for the delivery of a message from one process to another. RSManiaol

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

Oral. Total. Dated Sign (2) (5) (3) (2)

Socket Programming for TCP and UDP

CSE 461 Module 11. Connections

C18: Network Fundamentals and Reliable Sockets

Light & NOS. Dan Li Tsinghua University

Lecture 3: Socket Programming

Assignment 1. Due date February 6, 2007 at 11pm. It must be submitted using submit command.

The Transmission Control Protocol (TCP)

Tutorial on Socket Programming

(Refer Slide Time: 1:09)

Group-A Assignment No. 6

Socket programming. Complement for the programming assignment INFO-0010

Transcription:

BITS-Pilani Hyderabad Campus CS C461/IS C461/CS F303/ IS F303 (Computer Networks) Laboratory 4 Aim: To give an introduction to Socket Programming in TCP and UDP. TCP Socket Programming: A socket is the mechanism that most popular operating systems provide to give programs access to the network. It allows messages to be sent and received between applications (unrelated processes) on different networked machines. The sockets mechanism has been created to be independent of any specific type of network. A socket address is the combination of an IP address and a port number, much like one end of a telephone connection is the combination of a phone number and a particular extension. Based on this address, internet sockets deliver incoming data packets to the appropriate application process or thread. An Internet socket is characterized by a unique combination of the following: Local socket address: Local IP address and port number Remote socket address: Only for established TCP sockets. This is necessary since a TCP server may serve several clients concurrently. The server creates one socket for each client, and these sockets share the same local socket address from the point of view of the TCP server. Protocol: A transport protocol (e.g., TCP, UDP, raw IP, or others). TCP port 53 and UDP port 53 are consequently different, distinct sockets. Tools used: gedit, terminal

Experiment 1: Working of a TCP concurrent server 1. Download tcp_client.c and tcp_server.c from the CMS Website 2. Compile server first (as shown below). gcc -o tcp_server tcp_server.c 3. Similarly, compile the client using the following command. gcc -o tcp_client tcp_client.c 4. Run the server using the below command. After running, the server would wait for an incoming connection (as shown in the Figure.1)./tcp_server Fig1. Server waiting for connections 5. On a separate terminal window, run the client using./tcp_client <localhost> Fig2. Client waiting for User input 6. Enter a character as input and it will be echoed back by the server (Refer Figure.3). Use netstat (on client side) to see the status of server-client communication. Fig3. Client input-output

Fig4. Server output 7. A concurrent server can allow multiple clients to connect simultaneously. Fig.5: Concurrent server 8. Kill the server by using a 'kill' command. Use netstat at the client side to see the status of the TCP communication. Write your observations. (To start the server again, wait for a couple of seconds (Why?) ). Experiment 2: Modification of the TCP Client-Server programs 1. Download tcp_client.c and tcp_server.c from the CMS Website (Concurrent server) 2. Modify the filenames as tcp_client_str.c and tcp_server_str.c 3. Work in teams of two. One of you run the server, and the other should connect as a client. One of you should edit the server code, and the other should edit the client code. Use appropriate IP address(es). 4. Modify the program such that a string of 14 characters is sent as a message. Ensure the server echoes back the same string. 5. Compile server first (as shown below). gcc -o tcp_server_str tcp_server_str.c 6. Similarly, compile the client using the following command. gcc -o tcp_client_str tcp_client_str.c 7. Run the server using the below command../tcp_server_str 8. The server will start, waiting for a client to connect. On a separate terminal window, run the client using./tcp_client_str <server IP> 9. Type hi im client! in the client terminal window. As you see the figure.7, the same message is echoed back from the server.

Fig6. Client sending string Fig7: Server receiving String 10. Close the client window while the server is running. Observe the socket communication details using netstat at the client side. Questions Answer the following questions based on your understanding of the experiments. 1. Which field in the socket function specifies the type of transport layer protocol (like TCP, UDP, etc.)? 2. What is the IP address and port no. of the server? 3. What is the purpose of bind function? 4. Which of the functions mentioned below are blocking calls? a. socket b. connect c. bind d. listen e. accept f. send g. recv h. close 5. Which function in the client program involved in connection establishment? 6. Which function in the server program involved in connection establishment?

UDP Socket Programming: A datagram socket is a type of connectionless network socket, which is the sending or receiving point for packet delivery services. Each packet sent or received on a datagram socket is individually addressed and routed. Multiple packets sent from one machine to another may arrive in any order and might not arrive at the receiving computer. A datagram socket provides a symmetric data exchange interface without requiring connection establishment. Each message carries the destination address. Tools used: gedit, terminal Experiment 3: Working of an UDP Client-Server program 1. Download udp_client.c and udp _server.c from the CMS Website. 2. The programs are partially complete. Complete the rest of the program, so that, it compiles and runs successfully (Implement echo server described in Experiment.2.) 3. Compile server first (as shown below). gcc -o udp_server udp_server.c 4. Similarly, compile the client using the following command. gcc -o udp_client udp_client.c 5. Run the server using the below command../udp_server 6. The server will start, waiting for a client to connect. On a separate terminal window, run the client using./udp_client <localhost> 7. Enter a character as input and it will be echoed back by the server (Refer Figure.8). Observe connection details in netstat. Fig8: Client sending and receiving a character 8. To stop the server and client, click Ctrl +C in their respective terminals. (To start the server again, wait for a couple of seconds).

Experiment 4: Modification of the UDP Client-Server programs 1. Download udp_client.c and udp_server.c from the CMS Website 2. Modify the filenames as udp_client_n.c and udp_server_n.c 3. Modify the program such that a string is sent in the message. Ensure the server echoes back the same string. (Hint: modify read and write functions). 4. Compile server first (as shown below). gcc -o udp_server_n udp_server_n.c 5. Similarly, compile the client using the following command. gcc -o udp_client_n udp_client_n.c 6. Run the server using the below command../udp_server_n 7. The server will start, waiting for a client to connect. On a separate terminal window, run the client using./udp_client_n <server IP or localhost> 8. Type hello in the client terminal window. As you see the Figure.9, the same message is echoed back from the server. Fig9: Client sending and receiving a string 9. To stop the server and client, click Ctrl +C in their respective terminals. (To start the server again, wait for a couple of seconds). Answer the following questions based on your understanding of the experiment. 1. Using netstat, did you observe any 'listen' state of UDP communication? Reason out. 2. Can you differentiate between TCP being stream-based and UDP being datagram based? References Unix Manual: http://man7.org/linux/man-pages/man2/socket.2.html