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)

Slides:



Advertisements
Similar presentations
CS 4700 / CS 5700 Network Fundamentals
Advertisements

CSE 333 – SECTION 8 Networking and sockets. Overview Network Sockets IP addresses and IP address structures in C/C++ DNS – Resolving DNS names Demos.
Socket Programming Application Programming Interface.
1 MP2: P2P File Server Hoang Nguyen. 2 Outline Basic network concepts revisited –Client/Server, Peer-to-peer –IP address, TCP/UDP Basic network programming.
Data Communications and Networking (Third Edition)
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.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
Tutorial 8 Socket Programming
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Application Layer PART VI.
Sockets COS 518: Advanced Computer Systems Michael Freedman Fall
UNIX Sockets COS 461 Precept 1. Clients and Servers Client program – Running on end host – Requests service – E.g., Web browser Server program – Running.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
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.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Agenda  Terminal Handling in Unix File Descriptors Opening/Assigning & Closing Sockets Types of Sockets – Internal(Local) vs. Network(Internet) Programming.
Operating Systems Chapter 9 Distributed Communication.
Assignment 3 A Client/Server Application: Chatroom.
Elementary TCP Sockets
Sockets CIS 370 Lab 10 UMass Dartmouth. Introduction 4 Sockets provide a simple programming interface which is consistent for processes on the same machine.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
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.
Internet Applications and Network Programming Dr. Abraham Professor UTPA.
CS162B: IPv4 Socketing Jacob T. Chan. Socketing in the Real World  Most computer games are multiplayer in nature or have multiplayer components  DotA,
---- IT Acumens. COM IT Acumens. COMIT Acumens. COM.
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 :
1 COMP445 Fall 2006 Lab assignment 1. 2 STEP1: Get the name of the second party STEP2: Get phone number from white pages CALLERRECEIVER STEP1: Plug the.
ECEN “Internet Protocols and Modeling”, Spring 2012 Course Materials: Papers, Reference Texts: Bertsekas/Gallager, Stuber, Stallings, etc Class.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
Distributed Computing A Programmer’s Perspective.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Introduction to Socket
Socket Programming Lab 1 1CS Computer Networks.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Socket Programming Introduction. Socket Definition A network socket is one endpoint in a two-way communication flow between two programs running over.
Client/Server Socket Programming Project
Socket Programming.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
Socket Program Training 10/29/ TCP Client Socket ( ) Connect ( ) send ( ) Close ( ) send ( ) Read ( ) Accept ( ) recv ( ) Listen ( ) Bind ( ) Socket.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
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.
Socket programming in C. Socket programming with TCP Client must contact server server process must first be running server must have created socket (door)
1 Network Communications A Brief Introduction. 2 Network Communications.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
1 K. Salah Application Layer Module K. Salah Network layer duties.
Socket Programming Jignesh Patel Palanivel Rathinam connecting processes.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
Sockets Intro to Network Programming. Before the internet... Early computers were entirely isolated No Internet No network No model No external communications.
Sockets and Beginning Network Programming
MCA – 405 Elective –I (A) Java Programming & Technology
Socket Programming Cal Poly Pomona Young CS380.
Socket Programming in C
Socket Programming in C
Advanced Network Programming spring 2007
27.
Starting TCP Connection – A High Level View
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Presentation transcript:

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) handles the request and sends the response (result) back to the client. In database server, the client queries the server for records from the database, and the server looks up the records and responds to the client. The user on the client machine may not even know what machine in the network actually has the database. In fact, the database may be distributed across several machines on the network.

Client Server Model The Client needs to know the existence and the address of the server. However, the server does not need to know the existence or address of the client prior to the connection. Once a connection is established, both sides can send and receive information.

How to establish a connection? Both client and server will construct a socket. A socket is one end of an interprocess communication channel. The process to establish a socket on the client side is different than the process to establish a socket on the server side.

How to establish a socket on the client side Create a socket using the socket() system call. Connect the socket to the address of the server using the connect() system call Send and receive data. You can use read() and write() system calls. However, there are different ways to send and receive data.

How to establish a socket on the server side Create a socket using the socket() system call. Bind the socket to an address using the bind() system call. For a server socket on the Internet, an address consists of a port number of the host machine. Listen for the connections using the listen() system call. Accept a connection using the accept() system call Send and receive data. You can use read() and write() system calls. However, there are different ways to send and receive data.

Address domain and the socket type The client and server processes can communicate with each other only if their sockets are in the same domain and of the same type. Two widely used address domains are:  Unix domain (in which two processes share a common file system).  Internet domain (in which two processes run on any two hosts on the Internet)

Unix and Internet domains The address of a socket in the Unix domain is a character string, an entry in the file system. The address of a socket in the Internet domain is the Internet address (IP address) of the host machine. Each socket needs a port number (16 bits unsigned integers) on the host. The lower numbers are reserved in Unix for standard services (e.g. 21 is used as the port number for the FTP server). Generally, port number above 2000 are available.

Socket types Two widely used socket types are: Stream socket: treats communications as a continuous stream of characters.It uses TCP Datagram socket: reads entire message at one time. It uses UDP.

Sample Client and Server codes Files (client and server) are posted on the Internet. Download these two files (server.c and client.c) Compile them into two executable files, server and client. How to run server?  Start the server first.  If your server is running on a machine called Merlin, you need to pass the port number as an argument (any number between 2000 and 65535).  If the port number is already in use, the server will let you know and exit. Then select another port number.  To run server, type server 3000

How to run the client To run the client, you have to pass two arguments:  The name of the host on which the server is running  The port number on which the server is listening for connections.  To run client, type client Merlin 3000

A Server on the Internet domain /* A simple server in the internet domain using TCP The port number is passed as an argument */ #include #include // def. of data types used in system calls #include //def. of structures needed for sockets #include // constants and structures for Internet // domain addresses void error(char *msg) // func. Is called when system calls fail { perror(msg); exit(1); }

Server Code int main(int argc, char *argv[]) { int sockfd, newsockfd, portno, clilen; // sockfd, newsockfd=>file // descriptor, portno stores the port number on which the server // accepts connections, clilen=> size of the address of the client, n=> no. of char to read or write char buffer[256]; struct sockaddr_in serv_addr, cli_addr; //sockaddr_in => structure containing Internet address int n; if (argc < 2) { fprintf(stderr,"ERROR, no port provided\n"); exit(1); }