Networks and Client/Server Applications

Slides:



Advertisements
Similar presentations
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012.
Advertisements

COEN 445 Communication Networks and Protocols Lab 4
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.
Basic Socket Programming with Java. What is a socket?  Generally refers to a stream connecting processes running in different address spaces (across.
Socket Programming.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
1 Java Networking – Part I CS , Spring 2008/9.
Layer 7- Application Layer
CSCI 4550/8556 Computer Networks Comer, Chapter 3: Network Programming and Applications.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L22 (Chapter 25) Networking.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 1 Let’s get started. Let’s start by selecting an architecture from among.
Networks and Client/Server Applications. Basics of Client/Server One host computer can have several servers Several clients can connect to a server Client.
Fundamentals of Python: From First Programs Through Data Structures
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
Assignment 3 A Client/Server Application: Chatroom.
Socket Lab Info. Computer Network. Requirement Use TCP socket to implement a pair of programs, containing a server and a client. The server program shall.
1 ELEN602 Lecture 2 Review of Last Lecture Layering.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
Discussion 2 Sockets Programming Applets TCP UDP HTTP Delay Estimation
Application Layer 2-1 ESERCITAZIONE SOCKET PROGRAMMING.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 11.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012.
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 22.
Networks and Client/Server Applications Handling Multiple Clients Concurrently.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Socket Programming.
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.
LECTURE 10 Networking. NETWORKING IN PYTHON Many Python applications include networking – the ability to communicate between multiple machines. We are.
1 Dimension of Server Designs r Iterative vs Concurrent r Connection-oriented vs. connectionless r Stateful and stateless m Constrained by application.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
Java Networking I IS Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.
1 Network Communications A Brief Introduction. 2 Network Communications.
CLIENT (Browser) socket accept C1 C2 recv C2 recv send C2 send end_thread recv C3 send bind connect Web Server Proxy recv close C3 close C2 end_thread.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit9: Internet programming 1.
1 Issues in Client/Server Refs: Chapter 27 Case Studies RFCs.
Echo Networking COMP
Chapter 3 outline 3.1 Transport-layer services
Networks and Client/Server Applications
Sockets and Beginning Network Programming
Lecture 10 Networking.
Networking COMP
Beyond HTTP Up to this point we have been dealing with software tools that run on browsers and communicate to a server that generates files that can be.
Client/Server Example
Chapter 2 Application Layer
Clients and Servers 19-Nov-18.
UNIX Sockets Outline Homework #1 posted by end of day
Networks and Client/Server Applications
Clients and Servers 1-Dec-18.
Starting TCP Connection – A High Level View
Issues in Client/Server Programming
TA: Donghyun (David) Kim
William Stallings Data and Computer Communications
TCP/IP Sockets in Java: Practical Guide for Programmers
Message Passing Systems Version 2
Exceptions and networking
Message Passing Systems
Presentation transcript:

Networks and Client/Server Applications

Standalone vs Networked Apps All programs before the late 1960s were standalone programs, running on the user’s computer The first networked programs ran in the late 1960s By the late 1980s, many networked apps supported email and file sharing Then came the Web apps in the 1990s

Basics of Client/Server One host computer can have several servers Several clients can connect to a server Mail server Web server Host computer Network Client 1 Client 2 Client 3 Client 4

Network Addresses Every computer on a network has an address Every Internet address has two components: an IP name (such as "lambert") an IP address (such as "129.21.38.145") IP stands for Internet Protocol

Ports A port is a software abstraction of a physical space through which a client and a server can send messages Operating systems have several dedicated system ports and several free ports

Ports Ports are known by numbers For example, port 13 usually returns the day and time on the host computer Several processes can use the same port at the same time

Sockets A socket is a software abstraction that provides a communication link between a single server process and a single client process Several sockets can be created on the same port

Sockets Two things are required to create a socket: a valid IP address a port number Client and server then use input and output operations to send messages through the socket

The Basic Setup Host Server Port Client 1 Client 2 A server can be any application. A client can be any application.

Python Tools: Sockets The socket module includes functions classes for implementing network connections via sockets The client and sever each create their own sockets and run methods to talk to each other

Getting the Host Name and IP >>> import socket >>> socket.gethostname() 'smalltalk' >>> socket.gethostbyname(socket.gethostname()) '134.432.111.34'

Python Tools: Codecs Strings are transmitted as bytes, so they must be encoded before and decoded after transmission Strings are encoded and decoded using a codec, as defined in the codecs module

Encoding and Decoding Strings bytes(string, codec) -> an array of bytes codecs.decode(byteArray, codec) -> a string Consult the codecs doc for info on the possible codecs >>> from codecs import decode >>> data = bytes('Good luck on the final exam', 'ascii') >>> print(decode(data, 'ascii') Good luck on the exam!

The Role of the Server The server creates a socket and listens for requests from clients When a client request comes in, the server sends the appropriate response via the socket When the client disconnects, the server continues to listen for more requests

The Structure of a Server Program Import resources Set up and connect the server to the net While True: Accept a connection from a client Process the request for service A server runs forever, unless an exception is raised

Example: A Date/Time Server When a client connects, the server sends the current date and time When the client receives this information, it is displayed in the terminal request server client Date and time

Day/Time Server and Client

Example: A Day/Time Server from socket import * from time import ctime The socket module includes resources for sockets The ctime function returns the date and time

Example: A Day/Time Server from socket import * from time import ctime HOST = 'localhost' PORT = 21566 ADDRESS = (HOST, PORT) A socket is associated with the host computer’s IP address and a port number These data are organized in a tuple localhost supports a server and a client running on the same computer

Example: A Day/Time Server from socket import * from time import ctime HOST = 'localhost' PORT = 21566 ADDRESS = (HOST, PORT) server = socket(AF_INET, SOCK_STREAM) server.bind(ADDRESS) server.listen(5) socket returns a socket object of the type specified by its arguments bind and listen establish the socket’s connection to the net and listen for client requests

Example: A Day/Time Server from socket import * from time import ctime HOST = 'localhost' PORT = 21566 ADDRESS = (HOST, PORT) server = socket(AF_INET, SOCK_STREAM) server.bind(ADDRESS) server.listen(5) while True: print('Waiting for connection . . . ') client, address = server.accept() print('... connected from:', address) accept pauses until a client connects accept returns the client’s socket and address information

Example: A Day/Time Server from socket import * from time import ctime HOST = 'localhost' PORT = 21566 ADDRESS = (HOST, PORT) server = socket(AF_INET, SOCK_STREAM) server.bind(ADDRESS) server.listen(5) while True: print('Waiting for connection . . . ') client, address = server.accept() print('... connected from:', address) client.send(bytes(ctime() + '\nHave a nice day!', 'ascii')) client.close() send sends an encoded string to the client and close ends the connection

Example: A Day/Time Server from socket import * from time import ctime HOST = 'localhost' PORT = 21566 ADDRESS = (HOST, PORT) server = socket(AF_INET, SOCK_STREAM) server.bind(ADDRESS) server.listen(5) while True: print('Waiting for connection . . . ') client, address = server.accept() print('... connected from:', address) client.send(bytes(ctime() + '\nHave a nice day!', 'ascii')) client.close() server.close() # Never reached here, but useful if exception # handling is added

Example: A Day/Time Client from socket import * HOST = 'localhost' PORT = 21566 BUFSIZE = 1024 ADDRESS = (HOST, PORT) server = socket(AF_INET, SOCK_STREAM) Setup code for a client socket is very similar to the code for a server socket BUFSIZE (1 kilobyte here) indicates the number of bytes allowed for each input operation

Example: A Day/Time Client from socket import * HOST = 'localhost' PORT = 21566 BUFSIZE = 1024 ADDRESS = (HOST, PORT) server = socket(AF_INET, SOCK_STREAM) server.connect(ADDRESS) connect connects this socket to the server at the specified address

Example: A Day/Time Client from socket import * from codecs import decode HOST = 'localhost' PORT = 21566 BUFSIZE = 1024 ADDRESS = (HOST, PORT) server = socket(AF_INET, SOCK_STREAM) server.connect(ADDRESS) dayAndTime = decode(server.recv(BUFSIZE), 'ascii') print(dayAndTime) server.close() recv inputs an encoded string from the server (the date and time)

Continue in Chapter 10 Multithreading For Monday Continue in Chapter 10 Multithreading