Java Networking I IS 313 5.20.2003. Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.

Slides:



Advertisements
Similar presentations
Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
Advertisements

28.2 Functionality Application Software Provides Applications supply the high-level services that user access, and determine how users perceive the capabilities.
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.
Network Programming CS3250. References Core Java, Vol. II, Chapter 3. Book examples are available from
Davide Rossi 2002 Using Sockets in Java. 2Davide Rossi 2002 TCP/IP  A protocol is a set of rules that determine how things communicate with each other.
System Programming Practical session 10 Java sockets.
1 School of Computing Science Simon Fraser University CMPT 771/471: Internet Architecture and Protocols Socket Programming Instructor: Dr. Mohamed Hefeeda.
© 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.
I NTRODUCTION OF S OCKET P ROGRAMMING L.Aseel AlTurki King Saud University.
Chapter 26 Client Server Interaction Communication across a computer network requires a pair of application programs to cooperate. One application on one.
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.
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
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 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
1 Computer Communication & Networks Lecture 28 Application Layer: HTTP & WWW p Waleed Ejaz
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 12 Communicating over.
TCP/IP: Basics1 User Datagram Protocol (UDP) Another protocol at transport layer is UDP. It is Connectionless protocol i.e. no need to establish & terminate.
 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.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Copyright © Curt Hill, Client – Server Computing An important paradigm.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
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.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
© 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.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
ECEN “Internet Protocols and Modeling”, Spring 2012 Course Materials: Papers, Reference Texts: Bertsekas/Gallager, Stuber, Stallings, etc Class.
Presented by Rebecca Meinhold But How Does the Internet Work?
1 Client-Server Interaction. 2 Functionality Transport layer and layers below –Basic communication –Reliability Application layer –Abstractions Files.
Socket Programming Introduction. Socket Definition A network socket is one endpoint in a two-way communication flow between two programs running over.
1 Transport Protocols Relates to Lab 5. An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified.
Networking OSI (Open Systems Interconnection) model of computer networking, seven layers (the Application, Presentation, Session, Transport, Network, Data.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
1 COMP 431 Internet Services & Protocols Client/Server Computing & Socket Programming Jasleen Kaur February 2, 2016.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Java’s networking capabilities are declared by the classes and interfaces of package java.net, through which Java offers stream-based communications that.
Networking Mehdi Einali Advanced Programming in Java 1.
The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem.
Transport Protocols Relates to Lab 5. An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
Networking COMP
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.
Working at a Small-to-Medium Business or ISP – Chapter 7
Network Architecture Introductory material
Working at a Small-to-Medium Business or ISP – Chapter 7
File Transfer Protocol
The Internet and HTTP and DNS Examples
Review of Important Networking Concepts
Transport Protocols Relates to Lab 5. An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
Transport Protocols Relates to Lab 5. An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
Working at a Small-to-Medium Business or ISP – Chapter 7
Transport Protocols An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
Computer Networks Protocols
Transport Protocols Relates to Lab 5. An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
Presentation transcript:

Java Networking I IS

Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers

Quiz 3

Network layers

Packet-switched Network

Application-layer protocols  SMTP  HTTP  FTP  many others all rely on services of TCP/IP network

Client/Server Web Interaction

HTTP Protocol  Request “I want something”  Response “Here it is” or “Not found”  Headers  Body

HTTP Response Example

Need for Protocol  Client programs must know how to state requests  Server must know how to interpret  The protocol is the agreement  Important A weak or inflexible protocol limits what can be done A complex protocol may be difficult to implement

Example  Voting application  Design client applications – allow users to vote server – receives and counts votes

Need a Protocol  Example Establish credentials Transmit votes Verify

Implementing a protocol  States  Messages state transition data transmission

Example  States unauthenticated authenticated votes complete votes verified

Messages  State transition server: “credentials OK” client: “done with votes”  Data transmission client: “vote for candidate64 in race111”

Sockets  Bi-directional stream-oriented communication  Directed towards a host and port

Communicating with sockets  Server waits at a port  Client connects to a machine + port combination  Port number must be agreed upon often conventional (port 80 = http)  Bi-directional stream established

Java Sockets  Socket abstraction of TCP layer turns network into a pair of data streams address = machine + port  Two types ServerSocket Socket

Client Socket Details  Creating a socket s_socket = new Socket (host, 4445);  Once the socket exists s_socket.getOutputStream() s_socket.getInputStream()  Use when connecting to a host that supplies a service

Example  NIST time server  Protocol open connection send time string close connection

Server Socket  Create a listening socket serverSock = new ServerSocket (port);  Listen for clients Socket sock = serverSock.accept ();  Wait for a client connection A new socket is created  Use to offer a service

Example  EchoServer  Protocol open connection echo mode  read line  print “Echo: “ + line  until “BYE” input close connection

Demultiplexing  Port number Server sockets are created with a port number Connection sockets are assigned port numbers automatically  TCP “demultiplexes” Based on IP addresses and port numbers at both ends  Multiple connections to same “port” possible Each result of an “accept()” call is unique

Making the connection 1

Making the connection 2

Making the connection 3

Accept  Creates a new Socket associated with a different port  Result server can accept many connections  How to service them all?

Multi-threaded Servers  Typical network application > 80% waiting (network, file system) < 20% computation  Theoretically 5 simultaneous requests No change in response time

Multi-threaded Server for (;;) { Socket incoming = s.accept( ); System.out.println("Spawning " + i); Thread t = new ThreadedEchoHandler(incoming, i); t.start(); i++; }

Example  MultiThreaded Echo  Same protocol now multiple clients

Session  EchoServer is a session-based protocol  Each connection is a session we continue echoing for a client until we get BYE each client gets a dedicated thread  Possible problems client disconnects before BYE long waits between interactions wasted server resources

Stateless Protocol  No extended interaction  Answer request and end connection

Example  StatelessEchoServer  Protocol open connection read line echo line close connection

Problem  Creating and destroying Thread objects  Better solution Thread pooling