Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) 698 8427 - cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores.

Slides:



Advertisements
Similar presentations
© Janice Regan, CMPT 128, CMPT 371 Data Communications and Networking Socket Programming 0.
Advertisements

Universidad de Chile - Tupper 2007, Santiago - Fono: Fax: Módulo 9: Desarrollo de Aplicaciones.
Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores.
Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores.
Programming Servers Version Programming the Server What happens on the server when the client tries to establish a rendezvous ? The server starts.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 OSI Transport Layer Network Fundamentals – Chapter 4.
Basic Socket Programming with Java. What is a socket?  Generally refers to a stream connecting processes running in different address spaces (across.
Universidad de Chile - Tupper 2007, Santiago - Fono: Fax: Módulo 9: Desarrollo de Aplicaciones.
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.
Programming Applets How do Applets work ? This is an HTML page This is the applet’s code It has a link to an applet.
Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores.
System Programming Practical session 10 Java sockets.
Programming Servers October Programming the Server What happens on the server when the client tries to establish a rendezvous ? The server starts.
Network Programming. The biggest difficult part in networking programming lies in understanding networking not in using java networking package. Since.
An Introduction to Internetworking. Why distributed systems - Share resources (devices & CPU) - Communicate people (by transmitting data)
© 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.
WXES2106 Network Technology Semester /2005 Chapter 8 Intermediate TCP CCNA2: Module 10.
An Introduction to Internetworking. Algorithm for client-server communication with UDP (connectionless) A SERVER A CLIENT Create a server-socket (listener)and.
Programming Servers June Programming the Server What happens on the server when the client tries to establish a rendezvous ? The server starts listening.
Application Layer  We will learn about protocols by examining popular application-level protocols  HTTP  FTP  SMTP / POP3 / IMAP  Focus on client-server.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
Process-to-Process Delivery:
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
Application Layer 2-1 ESERCITAZIONE SOCKET 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.
1. I NTRODUCTION TO N ETWORKS Network programming is surprisingly easy in Java ◦ Most of the classes relevant to network programming are in the java.net.
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.
Fundamentals of Proxying. Proxy Server Fundamentals  Proxy simply means acting on someone other’s behalf  A Proxy acts on behalf of the client or user.
Chapter 2 Applications and Layered Architectures Sockets.
© Lethbridge/Laganière 2005 Chap. 3: Basing Development on Reusable Technology The Client-Server Architecture A distributed system is a system in.
Sockets Sockets A socket is an object that encapsulates a TCP/IP connection There is a socket on both ends of a connection, the client side and the server.
The InetAddress Class A class for storing and managing internet addresses (both as IP numbers and as names). The are no constructors but “class factory”
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
Java Sockets Tutorial Rahul Malik Nov 12, 2005.
CSC 480 Software Engineering Socket. What is Socket? A socket is one end-point of a two-way communication link between two programs running on the network.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Java Server Programming Web Interface for Java Programs.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
Network Architecture Protocol hierarchies Design Issues for the layers
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Prepared by Dr. Jiying Zhao University of Ottawa Canada.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
McGraw-Hill Chapter 23 Process-to-Process Delivery: UDP, TCP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Data Communication Networks Lec 13 and 14. Network Core- Packet Switching.
Java Networking I IS Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.
TCP/IP1 Address Resolution Protocol Internet uses IP address to recognize a computer. But IP address needs to be translated to physical address (NIC).
SOCKET PROGRAMMING WITH JAVA By Collin Donaldson.
1 Network Communications A Brief Introduction. 2 Network Communications.
The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem.
MCA – 405 Elective –I (A) Java Programming & Technology
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.
Networks and Client/Server Applications
Transport Layer Our goals:
Process-to-Process Delivery:
An Introduction to Internetworking
An Introduction to Internetworking
Programming Servers Feb 2009 Tokyo-Honjo.
Programming TCP Sockets
Process-to-Process Delivery: UDP, TCP
Message Passing Systems Version 2
Message Passing Systems
Presentation transcript:

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 1 Programming the Server  What happens on the server when the client tries to establish a rendezvous ?  The server starts listening to requests on a ServerSocket  After accepting the request the resulting connection is attached to another (normal) socket (same type as client’s socket)

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 2 Sockets at the Server Side (1)  The server should start by creating a server socket bound to a certain port according to the protocol of the service. ServerSocket listening; listening = new ServerSocket(5555);  This will create the socket but the server is still not listening. To do this we should apply the following method to the socket: Socket toClient = listening.accept();  This sentence works the following way:  accept() blocks the execution of the program until a request for a rendezvous from a client is received.  When the requirement arrives, a tcp connection is established between the two computers. The client receives in its socket one end of this link and the server the other. The server side’s socket (from the Socket class) is chosen conveniently by the system

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 3 Sockets at the Server Side(2)  At the server side we can apply the same methods to the “normal” socket as we did at the client side. Particularly we may need to open an input and an output data stream.  After this, the server should implement the communication protocol which was established and published (by any other possible mean). It is important that both side follow this protocol in order not to block the communication and/or miss some data. This mean nothing else than following the “turn taking” rules of writing to and reading from the socket and the format of the data to be exchanged.  Note that the server socket (and port) at which the server was originally listening to requests is not used anymore. This is a design issue.

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 4 We will program now a date server for a computer which has no one (for example, a MS-Windows computer) A Date Server Date server 13 Client 1) Create the server socket 2) start listening 4) close the connection 3) answer with the date in another socket DateServer DateClient2

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 5 We will program now a date server for a computer which has no one (for example, a MS-Windows computer) An Echo Server Date server 7 Client 1) Create the server socket 2) start listening 3) Request a line 4) answer with the same Do 3 & 4 until client disconnects or sends a line with ** EchoServer EchoClient2

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 6 Bla bla from keyboard Talk client Talk Server Let’s program something rather simple Bla bla The TalkServer waits for someone wishing to communicate The TalkClient asks for a host name and tries the redezvous After the communication is set up, everything the client user types in will be transmitted to the talk server and this will display it on the screenboard

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 7 Let’s see another example of simple client-server communication with TCP Open server socket port =4444 While(true) { accept call open reading from socket while (true) { read line from socket if (line.equals(“bye”)) break; write line to screen } //end of the call } s=new Socket(args[0],4444) open writing to socket while (true) { read line from keyboard write to socket if (line.equals(“bye”)) break; } TalkClient TalkServer

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 8 Sockets: File transfer (1)  We will now develop programs for transmitting files.  The one receiving the file starts listening for someone who wants to transmit a file (the server !!!)  The sender knows where (hostname and port number) the server is listening and sends a rendezvous request.  The data transfer is done at the byte level in order to allow the transfer of non textual files.

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 9 2)The sender tries a rendezvous with receiver 4) Send bytes 3) Read bytes from file5) Write bytes in file Repeat 3,4,5 until all the file is transmitted Transmitting files 1)The reciver starts listening for Requests to send (upload) files See ArchEnviador.java ArchRecibidor.java

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 10 1) Filename from keyboard 2) Request file 4) Send file 3) Read File5) Write file Repeat 3,4,5 until all the file is transmitted A more intelligent file server See ArchServer.java ArchCliente.java

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 11 Stateless vs. Stateful servers: the problem of reading a remote file by steps. File reading requests arrive with delay A SERVER A CLIENT Open file XYZ read first 50 bytes while (not end of file XYZ) read next 50 bytes close file ? Request open file XYZ Answer file XYZ exists and ready

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 12 A stateless server means it does not remember previous requests A SERVER A CLIENT Open file XYZ read first 50 bytes while (not end of file XYZ) read next 50 bytes close file ? Request read bytes 0 to 49 from file XYZ Answer the content of the bytes

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 13 The client must provide all the information again ! A SERVER A CLIENT Open file XYZ read first 50 bytes while (not end of file XYZ) read next 50 bytes close file ? Request read bytes 50 to 99 from file XYZ Answer the content of the bytes

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 14 This may cause a lot of network traffic, especially if there are many clients A SERVER A CLIENT Open file XYZ read first 50 bytes while (not end of file XYZ) read next 50 bytes close file ? Request read bytes X to X+50 from file XYZ Answer the content of the bytes

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 15 Stateful Server: it maintains some information abut what clients did A SERVER A CLIENT Open file XYZ read first 50 bytes while (not end of file XYZ) read next 50 bytes close file ? Request open file XYZ Answer: file pointer to file XYZ Pointer File Position 0 XYZ 0 1 FILE ZXY 50

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 16 The information the client has to pass to the server is much smaller A SERVER A CLIENT Open file XYZ read first 50 bytes while (not end of file XYZ) read next 50 bytes close file ? Request 0, read 50 Answer: the content Pointer File Position 0 XYZ 50 1 FILE ZXY 50

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 17 The information at the server should be updated with every request A SERVER A CLIENT Open file XYZ read first 50 bytes while (not end of file XYZ) read next 50 bytes close file ? Request 0, read 50 Answer: the content Pointer File Position 0 XYZ FILE ZXY 50

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 18 It is important to close the file !!! A SERVER A CLIENT Open file XYZ read first 50 bytes while (not end of file XYZ) read next 50 bytes close file ? Request 0, read 50 Answer: the content Pointer File Position 0 XYZ FILE ZXY 50

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 19 Communications: the networked approach  Every 2 applications which want to start a communication open an exclusive channel (hostnames and ports mut be known to each other)  We have n*(n-1)/2 channels for n applicatons  Advantages:  An exclusive channel, no bottlenecks  Drawbacks:  Every application must be aware of port and host address.  Management of incomming/outgoing members

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 20 The centralized (star) approach  Applications send their communications requirements to a server. This will forward the message to the final destinatary.  We have at most n communication channels  Advanatages:  Easier management of the communication  Drawbacks:  Server saturation.

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 21 Software Arquitecture: replicated applications  In a replicated schema an instance of the application is started at every place  The applications may differ from each other (since they are started independently) to support different roles.

Universidad de Chile - Tupper 2007, Santiago - Fono/Fax: (56 2) cec.uchile.cl Módulo ECI - 11: Fundamentos de Redes de Computadores 22 Software Arquitecture: centralized application  In a centralized schema there is only one application which sends it outputs to the screen (window server program) of all computers  It also collects the input from all them  Net meeting is a famous example of this approach Advantages and Drawbacks ?