Application Architecture



Similar documents
Socket Programming. Srinidhi Varadarajan

Socket Programming. Request. Reply. Figure 1. Client-Server paradigm

Porting applications & DNS issues. socket interface extensions for IPv6. Eva M. Castro. ecastro@dit.upm.es. dit. Porting applications & DNS issues UPM

Tutorial on Socket Programming

Introduction to Socket Programming Part I : TCP Clients, Servers; Host information

Socket Programming. Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur

Introduction to Socket programming using C

Implementing Network Software

TCP/IP - Socket Programming

NS3 Lab 1 TCP/IP Network Programming in C

Socket Programming in C/C++

Network Programming with Sockets. Process Management in UNIX

INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens

UNIX Sockets. COS 461 Precept 1

Unix Network Programming

Lab 4: Socket Programming: netcat part

Networks. Inter-process Communication. Pipes. Inter-process Communication

ELEN 602: Computer Communications and Networking. Socket Programming Basics

ICT SEcurity BASICS. Course: Software Defined Radio. Angelo Liguori. SP4TE lab.

Operating Systems Design 16. Networking: Sockets

The POSIX Socket API

IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking.

VMCI Sockets Programming Guide VMware ESX/ESXi 4.x VMware Workstation 7.x VMware Server 2.0

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software

BSD Sockets Interface Programmer s Guide

Writing Client/Server Programs in C Using Sockets (A Tutorial) Part I. Session Greg Granger grgran@sas. sas.com. SAS/C & C++ Support

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

CSE 333 SECTION 6. Networking and sockets

Computer Networks/DV2 Lab

DESIGN AND IMPLEMENT AND ONLINE EXERCISE FOR TEACHING AND DEVELOPMENT OF A SERVER USING SOCKET PROGRAMMING IN C

CS3250 Distributed Systems

IBM i Version 7.2. Programming Socket programming IBM

Socket = an interface connection between two (dissimilar) pipes. OS provides this API to connect applications to networks. home.comcast.

Limi Kalita / (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 5 (3), 2014, Socket Programming

Network Programming with Sockets. Anatomy of an Internet Connection

What is CSG150 about? Fundamentals of Computer Networking. Course Outline. Lecture 1 Outline. Guevara Noubir noubir@ccs.neu.

IP Network Layer. Datagram ID FLAG Fragment Offset. IP Datagrams. IP Addresses. IP Addresses. CSCE 515: Computer Network Programming TCP/IP

Network Programming TDC 561

Network Layers. CSC358 - Introduction to Computer Networks

Hands On Activities: TCP/IP Network Monitoring and Management

Client / Server Programming with TCP/IP Sockets

Hostnames. HOSTS.TXT was a bottleneck. Once there was HOSTS.TXT. CSCE515 Computer Network Programming. Hierarchical Organization of DNS

Software changes for Website and Application IPv6 Readiness

Generalised Socket Addresses for Unix Squeak

Programmation Systèmes Cours 9 UNIX Domain Sockets

Application. Transport. Network. Data Link. Physical. Network Layers. Goal

Writing a C-based Client/Server

Glossary of Technical Terms Related to IPv6

MATLAB/Simulink TCP/IP Communication

Computer Networks Network architecture

IPv6 Enabling CIFS/SMB Applications

Chapter 3. Internet Applications and Network Programming

UNIX. Sockets. mgr inż. Marcin Borkowski

Objectives of Lecture. Network Architecture. Protocols. Contents

Implementing and testing tftp

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

Chapter 6. About This Chapter. Before You Begin. Windows 2000 Naming Schemes. [Previous] [Next]

Application Layer. CMPT Application Layer 1. Required Reading: Chapter 2 of the text book. Outline of Chapter 2

Lecture 17. Process Management. Process Management. Process Management. Inter-Process Communication. Inter-Process Communication

Project 4: IP over DNS Due: 11:59 PM, Dec 14, 2015

Packet Sniffing and Spoofing Lab

First Workshop on Open Source and Internet Technology for Scientific Environment: with case studies from Environmental Monitoring

ADH8060/8066 GSM/GPRS Module

Network-Oriented Software Development. Course: CSc4360/CSc6360 Instructor: Dr. Beyah Sessions: M-W, 3:00 4:40pm Lecture 2

Networks class CS144 Introduction to Computer Networking Goal: Teach the concepts underlying networks Prerequisites:

IP Addressing. -Internetworking (with TCP/IP) -Classful addressing -Subnetting and Supernetting -Classless addressing

NetIQ Advanced Authentication Framework - MacOS Client

Application Development with TCP/IP. Brian S. Mitchell Drexel University

q Connection establishment (if connection-oriented) q Data transfer q Connection release (if conn-oriented) q Addressing the transport user

IP address format: Dotted decimal notation:

TCP/IP Network Essentials. Linux System Administration and IP Services

NAT TCP SIP ALG Support

Chapter 2: Remote Procedure Call (RPC)

Using IPM to Measure Network Performance

Elementary Name and Address Conversions

Application Technique. EtherNet/IP Socket Interface

How-to: DNS Enumeration

Lecture 2-ter. 2. A communication example Managing a HTTP v1.0 connection. G.Bianchi, G.Neglia, V.Mancuso

Cross-platform TCP/IP Socket Programming in REXX

Understanding TCP/IP. Introduction. What is an Architectural Model? APPENDIX

A Client Server Transaction. Introduction to Computer Systems /18 243, fall th Lecture, Nov. 3 rd

Computer Networks. Introduc)on to Naming, Addressing, and Rou)ng. Week 09. College of Information Science and Engineering Ritsumeikan University

Elementary Name and Address. Conversions

Homework 3 TCP/IP Network Monitoring and Management

Client-server Sockets

IP Subnetting and Addressing

Network Programming using sockets

EventSentry Overview. Part I Introduction 1 Part II Setting up SQL 2008 R2 Express 2. Part III Setting up IIS 9. Part IV Installing EventSentry 11

TCP/IP Fundamentals. OSI Seven Layer Model & Seminar Outline

Named Pipes, Sockets and other IPC

Unix System Administration

Communications and Networking

Application-layer protocols

Network Technologies

Communication Networks. Introduction & Socket Programming Yuval Rochman

Transcription:

A Course on Internetworking & Network-based Applications CS 6/75995 Internet-based Applications & Systems Design Kent State University Dept. of Science LECT-2 LECT-02, S-1 2 Application Architecture Today s Topic How to Build a Network Application We will build a baby Server/Client today! 3 LECT-02, S-4 Client Server Interaction Multiple Services on One LECT-02, S-5 LECT-02, S-6 1

Server Waits CLIENT Request Sent to Server CLIENT CLIENT Response Sent to Client Client Exits LECT-02, S-7 Server Waits Request Sent to Server Response Sent to Client Client Exits LECT-02, S-8 Application Platform Network-based Applications API (TLI/Socket) Operating System Services API to Network Network Protocols (TCP/IP/UDP) LECT-02, S-9 10 Network APIs What is Socket API? Transport Layer Interface (TLI) was developed in mid 1980s by AT&T with release 3 of system V UNIX. Later it became a part of Sun systems. Now this is available everywhere. Socket Application Program Interface can be used to access a network protocol stack from any programming language. Socket API is the original API developed by Berkeley UNIX group in late 70 s and early 80s. Available on BSD UNIX Systems. Socket API has been inspired by Unix openread-write-close file access paradigm (original is Multics). WinSock is the API version provided for Microsoft Windows. However, accessing network is substantially more complex than file access. LECT-02, S-11 LECT-02, S-12 2

Sockets & Files Socket Creation & Closing An integer called file descriptor is returned, when a file is opened. In the same way a socket descriptor is returned when a socket is opened. A file descriptors binds to a file when it is open. descriptor=socket(pfamily, type, protocol) pfamily =PF_INET PF_APPLETALK PF_UNIX PF_PUP type=sock_stream, SOCK_DGRAM, SOCK_RAW, etc. protocol=subtype of protocol family if any. But, a socket can be created without binding to a specific destination. Applications can choose when to bind Datagram binds each time when it sends, therefore same socket can be used to send to many. TCP binds once, and it remains, thus avoids repeated binding. LECT-02, S-13 Unix uses fork() and execv() to create and spawn new program. Child always inherits all parent sockets. UNIX maintains a count of owners. A process can close a socket by close(socket) LECT-02, S-14 Specifying a Local Address Initially a socket is created without any association to a local or remote address. For TCP/IP it means no protocol port number. Some application may not care (clients generally). Some do (all servers). The call: bind(socket, localaddress, addrlen) socket is the socket descriptor returned by socket() localaddress is a complex structure with several fields, and may vary for protocols. For TCP/IP it contains both the port number and the IP address of the host is in it. addrlen is the length of the address. LECT-02, S-15 Address Structures Barkley code defines a generic sockaddr structure to represent address of a connection end-point. struct sockaddr { u_char sa_len; u_char sa_family; char sa_data[14]; /*total length of the address*/ /*family of address*/ /*the address itself*/ }; Example: TCP/IP defines its own exact sockaddr_in: struct sockaddr_in { u_char sin_len; /*same as sa_len*/ u_char sin_family; /*same as sa_family*/ u_short_sin_port; /*protocol port number*/ struct in_addr sin_addr /*6B IP adress of the host*/ char sin_zero[8]; /*not used 6+8=14*/ }; Generally server calls bind to specify a server port number at which it will accept connection. A server on a multi-homed host can write down INADDR_ANY instead of the IP address to say it will accept the connection in any of the computers IP addresses. LECT-02, S-16 Listening for Connection listen allows a server to wait for a connection request from a remote client. Listen(socket, queuelength) socket is the descriptor that has been created and is bound to a local address. queuelength specifies how many request can wait while server is busy with one. OS maintains a separate request queue for each socket. It the queue is full, OS refuses new requests. LECT-02, S-17 Waiting for Accepting a Connection After a server executes socket-bind-listen, it can go to sleep by calling accept. The Operating System will wake up the server when there is a request in the request queue. newsock=accept(socket, &addr, &addrlen) socket is on which it was waiting, addr is a pointer, in which the address of the client will be returned by the OS. Addrlen is length of this address. newsock is a new socket created by system which has its destination pre-connected to the client. The server can keep on communicating with the requesting client with the newsocket, and close it when done. Meanwhile, the original socket remains intact to accept request from other clients. LECT-02, S-18 3

Connecting to a Destination Address Sending Data write(socket, buffer, bytelength) Initially a socket is created also without any destination address. An client application program must call connect to establish connection. writev(socket, iovector, vectorlen) iovector is an array of addresses and their lengths. The system gathers all the data. connect(socket, destaddr, destaddrlen) send(socket, message, length, flags) sendto(socket, message, length, flags, daddr, daddrlen) sendmsg(socket,messagestruct,flags) LECT-02, S-19 LECT-02, S-20 Receiving Data Obtaining Local & Peer Address read(descriptor, buffer, length) readv(descriptor, iovector, vectorlen) recv(socket, buffer, length, flags) recvfrom(socket,buffer,length,flags,fromaddr,addrlen) getpeername(socket, &destaddr,&addlen) getsockname(socket, &localaddr,&addlen) Obtaining & Setting Socket Options recvmsg(socket,messagestruct,flags) Getsockopt(socket,level,optionid,&optionval,&length) Setsockopt(socket,level,optionid,optionval,length) Example options are timeout parameters, allocated buffer space etc. LECT-02, S-21 LECT-02, S-22 Handling Multiple Request Obtaining & Setting Domain Names nready=select(ndesc,indesc,outdesc,execdesc,timeout) a call to select will allow server to wait till one of the descriptor is ready. ndesc=number of descriptors. System checks descriptors from 0 to ndesc-1. There are 3 bit masks to wait on a selected subset. Timeout says how long to wait. 0 means wait indefinitely. setdomainname(name,length) getdomainname(name, length) Network Byte Order Obtaining & Setting Hostnames gethostname(name,length) sethostname(name,length) Localshort=ntohs(netshort) Locallong=ntohl(netlong) Netshort=htons(localshort) Netlong=htonl(locallong) LECT-02, S-23 LECT-02, S-24 4

IP Address Manipulation Accessing Domain Name System String to 32 bit network byteordered address Address=inet_addr(string) Address=inet_network(string) address is a 32 bit IP address in network byte order. string is an ASCII stirng with IP in dotted decimal notation inet_network returns o for host part. Str=inet_ntoa(internetaddr) Internetaddr=inet_makeaddr(net,local) Net=inet_netof(internetaddr) Local=inet_lnaof(internetaddr) LECT-02, S-25 Each computer now also have a symbolic domain name. Such as www.kent.edu or shimana.facnet.mcs.kent.edu A set of designated computers (knows as DNS servers) scattered across the internet maintains the mapping of DNS to the actual IP. Translation from domain name to IP address or the opposite, requires communication with these servers. LECT-02, S-26 res_init() Accessing Domain Name System res_mkquery(op,dname,class,type, data, datalen,newrr, buffer,buflen) res-send(buffer,buflen,answer,anslen) dn_expand(msg,eom,compressed,full,fullen) dn_comp(full,compressed,cmprlen,prevptr,lastptr) ptr=gethostbyname(namestr) ptr=gethostbyaddr(add,len,type) Initialize DNS comm. Form Query. Send Query. Takes a domain name and returns a structure with information about the domain. Conversion between ASCII name and compressed domain name format. LECT-02, S-27 Obtaining Information about Network Services WHOIS a special server service, which allows a client in one machine to obtain information about user who has account in server machine. It runs on Port 43. Ptr=getservebyrname(name,proto) Name is the address of a desired service, and proto is usually TCP or UDP. It returns a structure which contains name of the service, a list of aliases, protocol identifier for this service, and an integer protocol port number. Ptr=getservbyport(port,proto) LECT-02, S-28 Obtaining information about Network & Protocol Ptr=getprotobynumber(number) Ptr=getnetbyname(namestr) Ptr=getnetbyaddr(netaddr, addrtype) Namestr is the name of the network in ASCII, ptr is a data structure which contain 32 bit IP address Each protocol has official name, number and registered aliases. These routines can be used to obtain complete information from name or port number of it. and other information about the net. Ptr=getprotobyname(name) LECT-02, S-29 An Example Service A client connect to a server, and waits for output. Server returns the count of the times it has been contacted by any client. Upon receiving the data the client prints it to screen. Command line arguments: client <hostname> <portname> server <portnumber> hostname and portnumbers are optional. Default host is localhost Default port is 5193. Output on client machine: This server has been contacted 10 times. LECT-02, S-30 5

server.c Click Here LECT-02, S-31 http://www.animasters.com/menu/vrml/estuary/estuaryintro.html LECT-02, S-32 Reference client.c ENGINEERING Internetworking with TCP/IP Volume III, Comer & Stevens. Click Here http://www.animasters.com/menu/vrml/estuary/estuaryintro.html LECT-02, S-33 LECT-02, S-34 6