Design, implementation and evaluation issues of local area network devices 期末 DEMO Elementary SCTP Socket Functions & Client/Server Example 694430007 陳旻槿.

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Socket Programming Application Programming Interface.
CS3516 (B10) HELP Session 2 Presented by Lei Cao.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
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.
Socket Programming.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
Sockets Programming Introduction © Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
Tutorial 8 Socket Programming
TDC561 Network Programming Camelia Zlatea, PhD Week 2 – part II: Socket Application Programming Interface.
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.
Lecture 10 Overview. Network API Application Programming Interface – Services that provide the interface between application and protocol software often.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
ECE 4110 – Internetwork Programming Client-Server Model.
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
Sockets CIS 370 Lab 10 UMass Dartmouth. Introduction 4 Sockets provide a simple programming interface which is consistent for processes on the same machine.
Sirak Kaewjamnong Computer Network Systems
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.
Sockets API Overview Sockets with UDP Sockets with TCP Fast Sockets (Fast UDP) IP Multicasting.
 Wind River Systems, Inc Chapter - 13 Network Programming.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
Ports Port - A 16-bit number that identifies the application process that receives an incoming message. Reserved ports or well-known ports (0 to 1023)
Remote Shell CS230 Project #4 Assigned : Due date :
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
Distributed Computing A Programmer’s Perspective.
Cli/Serv.: sockets 3/91 Client/Server Distributed Systems v Objectives –describe iterative clients and servers using the UDP protocol ,
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application.
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Socket Programming Lab 1 1CS Computer Networks.
Project 2: Socket Programming. Overview Sockets Working with sockets Client-Server example Project 1 Hints.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Intro to Socket Programming CS 360. Page 2 CS 360, WSU Vancouver Two views: Server vs. Client Servers LISTEN for a connection and respond when one is.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
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.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
UNIX Sockets Outline UNIX sockets CS 640.
1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level connection.Establishing.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Read: Chapters 1,2, 3, 4 Communications Client Server Ex: TCP/IP
Elementary UDP Sockets
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
CSI 4118 – UNIVERSITY OF OTTAWA
Interacting With Protocol Software
UNIX Sockets Outline Homework #1 posted by end of day
UDP Sockets Programming
TCP Sockets Programming
TCP/IP Socket Programming in C
Socket Programming(1/2)
Socket Programming Neil Tang 09/08/2008
CSI 4118 – UNIVERSITY OF OTTAWA
Presentation transcript:

Design, implementation and evaluation issues of local area network devices 期末 DEMO Elementary SCTP Socket Functions & Client/Server Example 陳旻槿

SCTP Socket Types Maintain consistency with the existing sockets APIs –The SCTP sockets API extension must stay consistency with the existing UDP,TCP,IPv4,and IPv6 sockets API. SCTP socket API comes in two forms: one-to- one and one-to-many. –The one-to-one used to be called the a “TCP style” socket. –The one-to-many at one time was known by the “UDP style” socket.

Functions Discussion socket() Applications calls socket() to create a socket descriptor to represent an SCTP endpoint. bind() Applications use bind() to pass an address to be associated with an SCTP endpoint to the system. listen() Applications use listen() to ready the SCTP endpoint for accepting inbound associations. accept() Applications use accept() call to remove an established SCTP association from the accept queue of the endpoint.

Functions Discussion connect() Applications use connect() to initiate an association to a peer. sendmsg() and recvmsg() An application uses sendmsg() and recvmsg() call to transmit data to and receive data from its peer. close() Applications use close() to gracefully close down an association. sctp_bindx() Allows an application to bind a set of addresses instead of one or all addresses.

sctp_initmsg() SCTP_INITMSG – Can be used to get or set the default INIT/INIT-ACK settings such as number of streams allowed in or requested out. sctp_sendmsg() This call will allow the caller to specify on the command line things like the stream number and other SCTPish information to be sent with a message. sctp_recvmsg() This call is used to receive a message but also a sctp_sndrcvinfo structure with details on the message (e.g. The stream number and stream sequence number).

SCTP one-to-one style socket A typical server in one-to-one style uses the following system call sequence to prepare an SCTP endpoint for servicing requests: 1. socket() 2. bind() 3. listen() 4. accept() 5. close()

A typical client uses the following system call sequence to setup an association with a server to request services: 1. socket() 2. connect() 3. close() After returning from connect(), the client uses send and recv calls to send out requests and receive responses from the server.

Server (connection-oriented protocol) socket() accept() send() or sendmsg() socket() connect() recv() or recvmsg() bind() send() or sendmsg() recv() or recvmsg() blocks until connection from client data (request) data (reply) Client (connection-oriented protocol) process request sctp_bindx() multiple addressessingle addresses listen() close() SCTP_INITMSG

one-to-many style socket A typical server using a one-to-many style socket will do a socket() call, followed by a listen() and sendmsg() / recvmsg(). Note that the connect() and accept() call are not needed. A typical server in this style uses the following socket calls in sequence to prepare an endpoint for servicing requests: 1. socket() 2. bind() 3. listen() 4. recvmsg() and sendmsg() 5. close()

A typical client uses the following calls in sequence to setup an association with a server to request services: 1. socket() 2. sendmsg() 3. recvmsg() 4. close()

Server socket() sendto( )/ sendmsg() socket() recvfrom() / recvmsg() bind() sendto( )/ sendmsg() recvfrom() / recvmsg() data (request) data (reply) Client process request listen() close()

Multi-streaming demo This example presents a server that implements a form of the daytime protocol. –This traditional server emits the current time to a connected client, but for SCTP, I emit the local time on stream 0 and Greenwich Mean Time (GMT) on stream 1.

socket() accept() sctp_ sendmsg() socket() connect() sctp_ sendmsg() bind() Sctp_recvmsg listen() close() Sctp_recvmsg Connection establishment Stream 0 Stream 1 Connection termination Client Server Sockets functions used in the multi-streaming daytime server and client

Server code (1/2) int main() { int listenSock, connSock, ret; struct sockaddr_in servaddr; char buffer[MAX_BUFFER+1]; time_t currentTime; /* Create SCTP TCP-Style Socket */ listenSock = socket( AF_INET, SOCK_STREAM, IPPROTO_SCTP ); /* Accept connections from any interface */ bzero( (void *)&servaddr, sizeof(servaddr) ); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl( INADDR_ANY ); servaddr.sin_port = htons(MY_PORT_NUM); /* Bind to the wildcard address (all) and MY_PORT_NUM */ ret = bind( listenSock,(struct sockaddr *)&servaddr, sizeof(servaddr) ); /* Place the server socket into the listening state */ listen( listenSock, 5 );

Server code (2/2) /* Server loop... */ while( 1 ) { /* Await a new client connection */ connSock = accept( listenSock,(struct sockaddr *)NULL, (int *)NULL ); /* New client socket has connected */ /* Grab the current time */ currentTime = time(NULL); /* Send local time on stream 0 (local time stream) */ snprintf( buffer, MAX_BUFFER, "%s\n", ctime(&currentTime) ); ret = sctp_sendmsg( connSock,(void *)buffer, (size_t)strlen(buffer), NULL, 0, 0, 0, LOCALTIME_STREAM, 0, 0 ); /* Send GMT on stream 1 (GMT stream) */ snprintf( buffer, MAX_BUFFER, "%s\n", asctime( gmtime( &currentTime ) ) ); ret = sctp_sendmsg( connSock,(void *)buffer, (size_t)strlen(buffer), NULL, 0, 0, 0, GMT_STREAM, 0, 0 ); /* Close the client connection */ close( connSock ); } return 0;}

Client code (1/2) int main() { int connSock, in, i, flags; struct sockaddr_in servaddr; struct sctp_sndrcvinfo sndrcvinfo; struct sctp_event_subscribe events; char buffer[MAX_BUFFER+1]; /* Create an SCTP TCP-Style Socket */ connSock = socket( AF_INET, SOCK_STREAM, IPPROTO_SCTP ); /* Specify the peer endpoint to which we'll connect */ bzero( (void *)&servaddr, sizeof(servaddr) ); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(MY_PORT_NUM); servaddr.sin_addr.s_addr = inet_addr( " " ); /* Connect to the server */ connect( connSock, (struct sockaddr *)&servaddr, sizeof(servaddr) ); /* Enable receipt of SCTP Snd/Rcv Data via sctp_recvmsg */ memset( (void *)&events, 0, sizeof(events) ); events.sctp_data_io_event = 1; setsockopt( connSock, SOL_SCTP, SCTP_EVENTS, (const void *)&events, sizeof(events) );

Client code (1/2) /* Expect two messages from the peer */ for (i = 0 ; i < 2 ; i++) { in = sctp_recvmsg( connSock, (void *)buffer, sizeof(buffer), (struct sockaddr *)NULL, 0, &sndrcvinfo, &flags ); /* Null terminate the incoming string */ buffer[in] = 0; if (sndrcvinfo.sinfo_stream == LOCALTIME_STREAM) { printf("(Local) %s\n", buffer); } else if (sndrcvinfo.sinfo_stream == GMT_STREAM) { printf("(GMT ) %s\n", buffer); } } /* Close our socket and exit */ close(connSock); return 0; }