Example Servers Pt 2 Objective: To discuss key aspects of various server implementations.

Slides:



Advertisements
Similar presentations
Advanced Sockets in UNIX / Linux References: Internetworking with TCP/IP (Comer) (Linux / POSIX Sockets Version) UNIX Network Programming Vol. 1, 2ed.(Stevens)
Advertisements

Socket Programming Application Programming Interface.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
1 Data Communications and Networking Socket Programming Part II: Design of Server Software Reference: Internetworking with TCP/IP, Volume III Client-Server.
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)
Winsock programming.  TCP/IP UDP TCP  Winsock #include wsock32.lib.
1 Socket Programming A crash-course in network programming…
CSTP FS97CS490D (cotter)1 Sockets Programming in UNIX References: Internetworking with TCP/IP Vol III - BSD version UNIX Network Programming - W. Richard.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.
Cs423-cotter1 Example Client Program Reference Comer & Stevens, Chapter 7.
1 Sockets Programming in Linux References: Internetworking with TCP/IP Vol III - Linux version UNIX Network Programming - W. Richard Stevens.
Tutorial on Socket Programming Data types and structures for writing client- server programs.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Fall 2000Datacom 11 Socket Programming Review Examples: Client and Server-Diagnostics UDP versus TCP Echo.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
IT1352-NETWORK PROGRAMMING AND MANAGEMENT
Sirak Kaewjamnong Computer Network Systems
The Application Layer Application Services (Telnet, FTP, , WWW) Reliable Stream Transport (TCP) Connectionless Packet Delivery Service (IP) Unreliable.
CS252: Systems Programming Ninghui Li Based on slides by Prof. Gustavo Rodriguez-Rivera Topic 17: Project 5.
Chapter 17 routing sockets. abstract Introduction datalink socket address structure reading and writing sysctl operation get_ifi_info function interface.
Lab #1: Network Programming using Sockets By J. H. Wang Nov. 28, 2011.
Review: How to create a TCP end point? What is the right format for sin_port and sin_addr in the sockaddr_in data structure? How many different ways we.
1 Example Servers Pt 1 Objective: To discuss key aspects of various server implementations.
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
I/O Multiplexing. TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
Cli/Serv.: sockets 3/91 Client/Server Distributed Systems v Objectives –describe iterative clients and servers using the UDP protocol ,
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Introduction to Socket
Socket Programming Lab 1 1CS Computer Networks.
Cs423-cotter1 Concurrency Issues in Client/Server Applications Chapters 15,16, 28.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Chapter 2 Applications and Layered Architectures Sockets.
C Programming in Linux Sockets. All Internet Applications use Sockets to Communicate Servers use passive sockets to listen Clients use active sockets.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology SDL_net Client-Server Example Spring 2012.
Single Process, Concurrent, Connection-Oriented Servers (TCP) (Chapter 12)
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.
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
实验讲解 1 、套接字的使用实例. D.E.Comer,D.L.Stevens, TCP/IP 网络互连技术 卷 III: 客户服务器编程和应用 Windows 套接字版 清华大学出版社 清华大学出版社 ServerClient Time.
Client-Server Programming and Applications. References Douglas Comer, David Stevens, “Internetworking with TCP/IP: Client-Server Programming and Applications”,
Socket programming in C. Socket programming with TCP Client must contact server server process must first be running server must have created socket (door)
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
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.
Chapter 02. Starting Windows Socket. IT COOKBOOK  Goal Error handling routine for Winsock function error Winsock startup and cleanup Socket creation.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
1 Vehicle Networking Networks Instruction 1 – Echo client/server in C Jeroen Voeten ES, 2012.
Sockets API Developing Applications using the Sockets API.
Socket programming in C
Socket programming Péter Verhás August 2002
Part 2 Socket Programming UDP.
CS 1652 Jack Lange University of Pittsburgh
Review: TCP Client-Server Interaction
Recitation 11 – 4/29/01 Outline Sockets Interface
Client-side Networking CSE 333 Spring 2018
Berkeley API Socket Programming
Berkeley API Socket Programming
Chapter 06. UDP Server/Client.
Client-side Networking CSE 333 Summer 2018
Socket Programming(1/2)
Chapter 04. TCP Server/Client.
Client-side Networking CSE 333 Winter 2019
Socket Programming Neil Tang 09/08/2008
Berkeley API Socket Programming
Socket programming in C
Presentation transcript:

Example Servers Pt 2 Objective: To discuss key aspects of various server implementations

Server Example Outline n Multi-Protocol Server –(Daytimed.cpp) n Multi-Service Server –(Superd.c)

3 Multiprotocol Server daytimed.c /* daytimed.cpp - main, daytime */ #include voiddaytime(char buf[]); voiderrexit(const char *,...); SOCKET passiveTCP(const char *, int); SOCKET passiveUDP(const char *); #define WSVERSMAKEWORD(2, 0) #defineQLEN 5 #defineLINELEN 128

4 Multiprotocol Server daytimed.c void main(int argc, char *argv[]) { char*service = "daytime";// service name charbuf[LINELEN+1];// line buffer structsockaddr_in fsin;// Request from address intalen;// from-address length SOCKETtsock; // TCP master socket SOCKETusock;// UDP socket fd_setrfds;// readable file descriptors intrv;WSADATAwsadata;

5 Multiprotocol Server daytimed.c switch (argc) { case1:break; case2:service = argv[1]; break; default: errexit("usage: daytimed [port]\n"); } if (WSAStartup(WSVERS, &wsadata) != 0) errexit("WSAStartup failed\n"); tsock = passiveTCP(service, QLEN); usock = passiveUDP(service); FD_ZERO(&rfds);

6 Multiprotocol Server daytimed.c while (1) { FD_SET(tsock, &rfds); FD_SET(usock, &rfds); if(select(FD_SETSIZE,&rfds,(fd_set*)0,(fd_set*)0, (struct timeval *)0) == SOCKET_ERROR) errexit("select error: %d\n", GetLastError()); if (FD_ISSET(tsock, &rfds)) { SOCKETssock;/* TCP slave socket*/ alen = sizeof(fsin); ssock = accept(tsock, (struct sockaddr *)&fsin, &alen); if (ssock == INVALID_SOCKET) errexit("accept failed: %d\n",GetLastError());

7 Multiprotocol Server daytimed.c daytime(buf); (void) send(ssock, buf, strlen(buf), 0); (void) closesocket(ssock); } if (FD_ISSET(usock, &rfds)) { alen = sizeof(fsin); rv = recvfrom(usock, buf, sizeof(buf), 0, (struct sockaddr *)&fsin, &alen); if (rv == SOCKET_ERROR) errexit("recvfrom: error %d\n",GetLastError()); daytime(buf); (void) sendto(usock, buf, strlen(buf), 0, (struct sockaddr *)&fsin, sizeof(fsin)); }

8 Multiprotocol Server daytimed.c /* * daytime - fill the given buffer with the time of day * */ void daytime(char buf[]) { time_tnow; (void) time(&now); sprintf(buf, "%s", ctime(&now)); }

9 Multi-service Server - superd.c /* superd.cpp - main, doTCP */ #include #defineUDP_SERV0 #defineTCP_SERV1 struct service { char*sv_name; char sv_useTCP; SOCKET sv_sock; void(*sv_func)(SOCKET); }; voidTCPechod(SOCKET), TCPchargend(SOCKET), TCPdaytimed(SOCKET),TCPtimed(SOCKET);

10 Multi-service Server - superd.c SOCKETpassiveTCP(const char *, int); SOCKETpassiveUDP(const char *); voiderrexit(const char *,...); voiddoTCP(struct service *); struct service svent[] ={ { "echo", TCP_SERV, INVALID_SOCKET, TCPechod }, { "chargen", TCP_SERV, INVALID_SOCKET, TCPchargend }, { "daytime", TCP_SERV, INVALID_SOCKET, TCPdaytimed }, { "time", TCP_SERV, INVALID_SOCKET, TCPtimed }, { 0, 0, 0, 0 }, }; #define WSVERSMAKEWORD(2, 0) #defineQLEN 5 #defineLINELEN 128 externu_shortportbase;/* from passivesock()*/

11 Multi-service Server - superd.c void main(int argc, char *argv[]) { struct service*psv;// service table pointer fd_setafds, rfds;/* file descriptors WSADATAwsdata; switch (argc) { case 1:break; case 2:portbase = (u_short) atoi(argv[1]); break; default:errexit("usage: superd [portbase]\n"); } if (WSAStartup(WSVERS, &wsdata)) errexit("WSAStartup failed\n"); FD_ZERO(&afds);

12 Multi-service Server - superd.c for (psv = &svent[0];psv->sv_name; ++psv) { if (psv->sv_useTCP) psv->sv_sock = passiveTCP(psv->sv_name, QLEN); else psv->sv_sock = passiveUDP(psv->sv_name); FD_SET(psv->sv_sock, &afds); }

Multi-service Server - superd.c while (1) { memcpy(&rfds, &afds, sizeof(rfds)); if (select(FD_SETSIZE, &rfds, (fd_set *)0, (fd_set *)0,(struct timeval *)0) == SOCKET_ERROR) errexit("select error: %d\n", GetLastError()); for (psv=&svent[0]; psv->sv_name; ++psv) { if (FD_ISSET(psv->sv_sock, &rfds)) { if (psv->sv_useTCP) doTCP(psv); else psv->sv_func(psv->sv_sock); }

14 Multi-service Server superd.c /* * doTCP - handle a TCP service connection request * */ void doTCP(struct service *psv){ struct sockaddr_in fsin;// Request from address intalen;/* from-address length*/ SOCKETssock; alen = sizeof(fsin); ssock = accept(psv->sv_sock,(struct sockaddr*)&fsin,&alen); if (ssock == INVALID_SOCKET) errexit("accept: %d\n", GetLastError()); if (_beginthread((void (*)(void *))psv->sv_func, 0, (void *)ssock) == (unsigned long) -1) errexit("_beginthread: %s\n", strerror(errno)); }

Summary n Servers can use different concurrency techniques to support multiple services at the same time. n Multiprotocol servers support a single server, but through multiple protocols n Multiservice servers share a common infrastructure (process context, etc.) across a number of small, low utilization servers to improve the efficiency of service support.