SCTP Client / Server example

Slides:



Advertisements
Similar presentations
Echo server The client reads a line of text from its standard input and writes the line to the server The server reads the line from its network input.
Advertisements

Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Socket Programming. Basics Socket is an interface between application and network – Application creates a socket – Socket type dictates the style of communication.
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.
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.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
Chapter 10 SCTP Client / Server example. Simple echo server using SCTP protocol Send line of text from client to server Server sends the same line back.
Design, implementation and evaluation issues of local area network devices 期末 DEMO Elementary SCTP Socket Functions & Client/Server Example 陳旻槿.
Sockets Programming Introduction © Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
TDC561 Network Programming Camelia Zlatea, PhD Week 2 – part II: Socket Application Programming Interface.
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
I/O Multiplexing Capability of tell the kernel that wants to be notified when one or more I/O conditions are ready. For example, I/O data is available.
1) The server should be concurrent. This implies that it should loop infinitely, listening for clients requests. It should NOT terminate after accepting.
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
Chapter 23 Advanced SCTP Sockets. SCTP Sockets, recall ● Stream Control Transmission Protocol ● Multi-homed ● Association, instead of connection ● IPV4.
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
ECE453 – Introduction to Computer Networks Lecture 15 – Transport Layer (II)
ECE 4110 – Internetwork Programming Client-Server Model.
1 TCP Client-Server Example TCP echo server: main and str_echo TCP echo client: main and str_cli Normal startup and termination POSIX signal handling Handling.
Assignment 3 A Client/Server Application: Chatroom.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
UNIX Network Programming1 UNIX Network Programming 2nd Edition.
Chapter 8 Elementary UDP Socket. Contents u recvfrom and sendto Function u UDP Echo Server( main, de_echo Function) u UDP Echo Client( main, de_cli Function)
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.
Chapter 2 Applications and Layered Architectures Sockets.
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)
TELE 402 Lecture 4: I/O multi … 1 Overview Last Lecture –TCP socket and Client-Server example –Source: Chapters 4&5 of Stevens’ book This Lecture –I/O.
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
CSCE 515: Computer Network Programming Select Wenyuan Xu Department of Computer Science and Engineering.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
Advanced Sockets API-II Vinayak Jagtap
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.
Introduction A Simple Daytime Client A Simple Daytime Server
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
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.
OS view of networking – Sockets API (an exercise in planning for the future) David E. Culler CS162 – Operating Systems and Systems Programming Lecture.
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem.
The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem.
Chapter 9: Transport Layer
Chapter 3 Transport Layer
Sockets and Beginning Network Programming
Instructor Materials Chapter 9: Transport Layer
Read: Chapters 1,2, 3, 4 Communications Client Server Ex: TCP/IP
CS 1652 Jack Lange University of Pittsburgh
Elementary UDP Sockets
CH5 TCP Client - Server Example:
Socket Programming in C
CHAPTER 8 ELEMENTARY UDP SOCKETS
Client/Server Example
Chapter 8 Elementary UDP Socket
UNIX Domain sockets The Linux Programming Interface (ch 57)
Chapter 5 (part 1) TCP Client /Server Example By: Lim Meng Hui.
TCP/IP Socket Programming in C
Elementary UDP Sockets connectionless, unreliable, datagram
Socket Programming(1/2)
TCP Client-Server Example
Internet Networking recitation #8
Presentation transcript:

SCTP Client / Server example Chapter 10 SCTP Client / Server example

Simple echo server using SCTP protocol Send line of text from client to server Server sends the same line back to the client Iterative server

Client Client reads a single line of text from standard input Text is send in [#]text format. # represents SCTP stream number where text is sent Server Reads the text from the network Increases the SCTP stream number by one (# in [#]text) Sends the message back to the client on this new stream Client Reads the reply message and prints it to standard output Stream number, sequence number and text string is printed

SCTP One-to-Many-Style Streaming Echo Server: main Function SCTP streaming echo server

Server: Stream increment Stream increment option If command line option is passed to program, program decides whether to increment stream number of incoming messages if (argc == 2) stream_increment = atoi(argv[1]); Server: Create an SCTP socket sock_fd = Socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

Server: Bind address Bind any incoming address to certain server port. bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(SERV_PORT); Bind(sock_fd, (SA *) &servaddr, sizeof(servaddr)); Server: Create an SCTP socket

Server: Set up for notification Server changes its notification subscription for the one-to-many SCTP socket. This allows server to see the stream number where the message arrived. bzero(&evnts, sizeof(evnts)); evnts.sctp_data_io_event = 1; Setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof(evnts));

Server: Incoming associations Server enables incoming associations so it can listen the server socket for incoming messages. Listen(sock_fd, LISTENQ); After which server will enter the main loop Server: Wait for messages Initialize size of client socket address structure. Block until message arrives. len = sizeof(struct sockaddr_in); rd_sz = Sctp_recvmsg(sock_fd, readbuf, sizeof(readbuf), (SA *)&cliaddr, &len, &sri,&msg_flags);

Server: Increment stream number Check increment flag and increase stream stream number is flag is set. If number is too large then number is set to 0. if(stream_increment) { sri.sinfo_stream++; if(sri.sinfo_stream >=sctp_get_no_strms(sock_fd, (SA *)&cliaddr,len)) sri.sinfo_stream = 0; }

Server: Send message back Sending back the message to the client Sctp_sendmsg(sock_fd, readbuf, rd_sz, (SA *)&cliaddr, len, sri.sinfo_ppid, sri.sinfo_flags, sri.sinfo_stream, 0, 0); Server: Finish? Program runs forever until it is shutdown with an external signal. for ( ; ; ) { … }

SCTP One-to-Many-Style Streaming Echo Client: main Function SCTP streaming echo client main

Client: Validate arguments Arguments: host and echo flag. if(argc < 2) err_quit("Missing host argument - use '%s host [echo]'\n", argv[0]); if(argc > 2) { printf("Echoing messages to all streams\n"); echo_to_all = 1; } Client: Create a socket Create an SCTP socket sock_fd = Socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);

Client: Set up server address Use given server address and well known port number to construct server address structure using Inet_pton(). bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(SERV_PORT); Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

Client: Set up for notifications Explicitly setting notification subscription for one-to-many socket. bzero(&evnts, sizeof(evnts)); evnts.sctp_data_io_event = 1; Setsockopt(sock_fd,IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof(evnts));

Client: Echo processing If flag is not set then sctpstrcli() is called. Else sctpstr_cli_echoall() is called. if(echo_to_all == 0) sctpstr_cli(stdin,sock_fd,(SA *)&servaddr,sizeof(servaddr)); else sctpstr_cli_echoall(stdin,sock_fd,(SA*)&servaddr,sizeof(servaddr)); These functions are shown later. Client: Finish: When all is done, client closes socket and returns zero. Close(sock_fd); return(0);

10.4 SCTP Streaming Echo Client: str_cli Function

Client: Initialize Initialize structure and enter loop. Block until user inputs line of text. bzero(&sri,sizeof(sri)); while (fgets(sendline, MAXLINE, fp) != NULL) { Client: Validate input Validate given input from the user. if(sendline[0] != '[') { printf("Error, line must be of the form '[streamnum]text'\n"); continue; }

Client: Stream number Stream number is translated from the user input and put into the structure. sri.sinfo_stream = strtol(&sendline[1],NULL,0); Client: Send message Message is sent. out_sz = strlen(sendline); Sctp_sendmsg(sock_fd, sendline, out_sz, to, tolen, 0, 0, sri.sinfo_stream, 0, 0);

Client: Send mesage Client: Display message Client: Wait for responseProgram blocks until message is received back from the server. len = sizeof(peeraddr); rd_sz = Sctp_recvmsg(sock_fd, recvline, sizeof(recvline), (SA *)&peeraddr, &len, sri,& msg_flags); Client: Display message Received message is displayed to standard output. printf("From str:%d seq:%d (assoc:0x%x):", sri.sinfo_stream,sri.sinfo_ssn, (u_int)sri.sinfo_assoc_id); printf("%.*s",rd_sz,recvline);

Client: Finish? Program reads lines from user until it is terminated by an external signal. Head-of-Line blocking Head-of-Line blocking occurs when TCP segment is lost and latter segments arrive out of order. All the subsequent segments are held until the lost segment is retransmitted. This ensures data arrives to the application in the order it was sent.

10.5 Exploring Head-of-Line Blocking Sending three pictures over one TCP connection Sending three pictures over three SCTP streams

Exploring Head-of-Line Blocking

SCTP blocking of streams SCTP allows multiple streams over single connection. Each stream can be transmitted independent of other streams. Blocking of one stream for retransmission does not block other streams. Client: Initialize and read input Initialize data structures. Enter loop and read user input. bzero(sendline,sizeof(sendline)); bzero(&sri,sizeof(sri)); while (fgets(sendline, SCTP_MAXLINE - 9, fp) != NULL) {

Client: Process user input Process given user input. strsz = strlen(sendline); if(sendline[strsz-1] == '\n') { sendline[strsz-1] = '\0'; strsz--; } Send message to each stream. Append .msg. and stream number to each message for visual help of tracking messages. for(i=0;i<SERV_MAX_SCTP_STRM;i++) { snprintf(sendline + strsz, sizeof(sendline) - strsz, ".msg.%d", i); Sctp_sendmsg(sock_fd, sendline, sizeof(sendline), to, tolen, 0, 0, i, 0, 0);

Client: Read, display and loop Block until incoming data comes from streams. Display message and move to read next. for(i=0;i<SERV_MAX_SCTP_STRM;i++) { len = sizeof(peeraddr); rd_sz = Sctp_recvmsg(sock_fd, recvline, sizeof(recvline), (SA *)&peeraddr, &len, &sri,&msg_flags); printf("From str:%d seq:%d (assoc:0x%x):", sri.sinfo_stream,sri.sinfo_ssn, (u_int)sri.sinfo_assoc_id); printf("%.*s\n",rd_sz,recvline); } After last message is read, loop back to user input.

Client: Modifications Send two messages to each stream to see messages are being held for reordering. for(i=0;i<SERV_MAX_SCTP_STRM;i++) { snprintf(sendline + strsz, sizeof(sendline) - strsz, ".msg.%d 1", i); Sctp_sendmsg(sock_fd, sendline, sizeof(sendline), to, tolen, 0, 0, i, 0, 0); snprintf(sendline + strsz, sizeof(sendline) - strsz, ".msg.%d 2", i); } for(i=0;i<SERV_MAX_SCTP_STRM*2;i++) { len = sizeof(peeraddr);

Number of streams Termination: FreeBSD KAME implementation: default 10 streams at start. Change must be made on the socket before an association is made. if (argc == 2) stream_increment = atoi(argv[1]); sock_fd = Socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); bzero(&initm,sizeof(initm)); initm.sinit_num_ostreams = SERV_MORE_STRMS_SCTP; Setsockopt(sock_fd, IPPROTO_SCTP, SCTP_INITMSG, &initm, sizeof(initm)); Termination: Two possible methods for closing one-to-many association: Close after sending message (eof) Close immediately (abort)

Termination: eof Server wishes to shutdown an association after sending message Set flag MSG_EOF in the reply message structure. Sctp_sendmsg(sock_fd, readbuf, rd_sz, (SA *)&cliaddr, len, sri.sinfo_ppid, (sri.sinfo_flags | MSG_EOF), sri.sinfo_stream, 0, 0); }

Termination: abort Server wishes to shutdown an association immediately. Set flag MSG_ABORT in the reply message structure. Forces immediate termination with an ABORT chunk. Any data not transmitted will be discarded. strcpy(byemsg,"goodbye"); Sctp_sendmsg(sock_fd, byemsg, strlen(byemsg), (SA *)&servaddr, sizeof(servaddr), 0, MSG_ABORT, 0, 0, 0); Close(sock_fd); Even if association has been aborted, socket descriptor still needs to be freed with Close().

Summary

References – Books Rudoff, Addison-Wesley, 2004, ISBN 0-13-141155-1 UNIX Network Programming; The Sockets Networking API, Vol. 1, 3rd ed, W. Richard Stevens, Bill Fenner, Andrew M. Rudoff, Addison-Wesley, 2004, ISBN 0-13-141155-1 chapter 9: Elementary SCTP Sockets chapter 10: SCTP Client/Server Example chapter 23: Advanced SCTP Sockets