UDP and Multi-thread Socket Programming

Slides:



Advertisements
Similar presentations
Nonblocking I/O Blocking vs. non-blocking I/O
Advertisements

Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Transport Layer3-1 Transport Overview and UDP. Transport Layer3-2 Goals r Understand transport services m Multiplexing and Demultiplexing m Reliable data.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Generic Transport Service Primitives Listen –notify Transport layer a call is expected Connect –establish Transport layer connection Send (or Write) Receive.
Socket Programming.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
1 Java Networking – Part I CS , Spring 2008/9.
Tutorial 8 Socket Programming
1 Generic Transport Service Primitives Listen –notify Transport layer a call is expected Connect –establish Transport layer connection Send (or Write)
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
2: Application Layer 1 Chapter 2 Application Layer Computer Networking: A Top Down Approach, 5th edition. Jim Kurose, Keith Ross Addison-Wesley, April.
UNIX Sockets COS 461 Precept 1.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
ECE 4110 – Internetwork Programming Client-Server Model.
Hands On Networking Socket Programming Ram P Rustagi, ISE Dept Abhishek Gupta, ISE Dept Laxmi Kuber, MCA Dept June 28-30, 2012.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Fall 2000Datacom 11 Lecture 4 Socket Interface Programming: Service Interface between Applications and TCP.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
University of Calgary – CPSC 441.  UDP stands for User Datagram Protocol.  A protocol for the Transport Layer in the protocol Stack.  Alternative to.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
Sockets CIS 370 Lab 10 UMass Dartmouth. Introduction 4 Sockets provide a simple programming interface which is consistent for processes on the same machine.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
Nonblocking I/O Blocking vs. non-blocking I/O Nonblocking input, output, accept, and connect Readings –UNP Ch16 1.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
UNIT8: SOCKETS Topics Introduction to sockets Socket Addresses
Chapter 3: Transport Layer Our goals: r understand principles behind transport layer services: m multiplexing/demultipl exing m reliable data transfer.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
Socket Programming.
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
Today’s topic: UDP Reliable communication over UDP.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Review: –Concurrent server and multiplexed server How they work? Which one is better?
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Review: – Why layer architecture? – peer entities – Protocol and service interface – Connection-oriented/connectionless service – Reliable/unreliable service.
Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
UNIX Sockets Outline UNIX sockets CS 640.
©The McGraw-Hill Companies, Inc., 2000© Adapted for use at JMU by Mohamed Aboutabl, 2003Mohamed Aboutabl1 1 Chapter 16 Socket Interface.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
1 Dimension of Server Designs r Iterative vs Concurrent r Connection-oriented vs. connectionless r Stateful and stateless m Constrained by application.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Sockets API Developing Applications using the Sockets API.
SOCKET PROGRAMMING Presented By : Divya Sharma.
UDP Socket Programming
UNIX Sockets COS 461 Precept 1.
CS 1652 Jack Lange University of Pittsburgh
Socket Programming in C
CHAPTER 8 ELEMENTARY UDP SOCKETS
Transport layer API: Socket Programming
Network Programming CSC- 341
UNIX Sockets Outline Homework #1 posted by end of day
Socket Programming in C
Chapter 16 Socket Interface.
CSC Advanced Unix Programming, Fall 2015
Chapter 06. UDP Server/Client.
Socket Programming with UDP
Presentation transcript:

UDP and Multi-thread Socket Programming

UDP (User Datagram Protocol) Another transport layer protocol (recall TCP). Difference from TCP: TCP guarantees reliable data transmission by establishing connection between client and server. UDP does not establish connection between server and client. It is a connection-less protocol. UDP, thus, does not guarantee the arrival, arrival time and content of the message.

UDP Socket Programming Overview UDP Server socket() sendto() recvfrom() UDP Client bind() Blocking function close()

UDP Socket Programming Syntax: int socket(int family, int type, int protocol); To create a UDP socket: int sd = socket(AF_INET,SOCK_DGRAM,0);

UDP Socket Programming sendto() and recvfrom() Syntax: sendto(int sd,void* buf,int bufLen,int flags,struct sockaddr* saddr,int addrlen); recvfrom(int sd,void* buf,int bufLen,int flags,struct sockaddr* saddr,int* addrlen); Example:

UDP Socket Programming sendto() and recvfrom() Return value: how many bytes are successfully sent. The return value may not be equal to the argument bufLen. Use a while loop to send and receive data.

UDP Socket Programming Bi-direction communication. There is a struct sockaddr* saddr argument in recvfrom() function, after executing recvfrom(), the address of the sender is thus stored in *saddr. We can then send the data using the address *saddr. See the sample codes for more information.

Demo: UDP-based Heartbeat Client sends heartbeat to server every three seconds. Server sends a response after receiving a heartbeat.

Multi-thread Socket Programming Recall the blocking functions in the first tutorial. The accept(), recv() and recvfrom() function. With a single thread, the program are blocked by one function and cannot proceed other operations. Consider a chat program, how can a client send out a message while the program is blocked by recv() function?

Example: TCP-Based Chatting Program. We extend the server and client program in the sample codes of first tutorial. We want both server and client able to send and receive messages from the other end. Problem: How to send message if the program is blocked by a recv() function? To send a message, we first send a 4-byte integer of the message length and then the message.

Design For both server and client sides, we have two threads: Main thread: read message from standard input and send to the other end. The worker thread: receive message and send to the other end.

Design Mater thread Establish connection Create thread Wait for input Send message Worker thread Recv message print message The recv() function just block the worker thread, instead of the whole program.

Basic Principle Do not let blocking functions affect other operations. Question: In the heartbeat example, both server and client need to do send and receive. Why do not we use a multi-thread model?

Q&A