Sockets For Servers Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.

Slides:



Advertisements
Similar presentations
1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
Advertisements

1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
UDP Datagrams and Sockets Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Prepared By E. Musa Alyaman1 Java Network Programming TCP.
Socket Programming.
1 Java Networking – Part I CS , Spring 2008/9.
WECPP1 Java networking Jim Briggs based on notes by Amanda Peart based on Bell & Parr's bonus chapter
Programming project #4 1 CS502 Spring 2006 Programming Project #4 Web Server CS-502 Operating Systems Spring 2006.
1 Web Search Interfaces. 2 Web Search Interface Web search engines of course need a web-based interface. Search page must accept a query string and submit.
Definitions, Definitions, Definitions Lead to Understanding.
13-Jul-15 Sockets and URLs. 2 Sockets A socket is a low-level software device for connecting two computers together Sockets can also be used to connect.
CS-3103 & CS-502, Summer 2006 Programming Project #31 Programming Project #3 Web Server CS-3103 & CS-502 Operating Systems.
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
Networking java.net package, which provides support for networking. Its creators have called Java “programming for the Internet.” Socket :- A network socket.
Web Client/Server Communication A290/A590, Fall /09/2014.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
HTTP; The World Wide Web Protocol
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Implementing ISA Server Publishing. Introduction What Are Web Publishing Rules? ISA Server uses Web publishing rules to make Web sites on protected networks.
Postacademic Interuniversity Course in Information Technology – Module C1p1 Contents Data Communications Applications –File & print serving –Mail –Domain.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
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.
DBI Representation and Management of Data on the Internet.
Operating Systems Recitation 9, May 19-20, Iterative server Handle one connection request at a time. Connection requests stored in queue associated.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
 TCP (Transport Control Protocol) is a connection-oriented protocol that provides a reliable flow of data between two computers.  TCP/IP Stack Application.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
---- IT Acumens. COM IT Acumens. COMIT Acumens. COM.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
Java Sockets Programming
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Socket Programming Using JAVA Asma Shakil Semester 1, 2008/2009.
Sockets For Clients Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
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.
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.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 7 Omar Meqdadi Department of Computer Science and Software Engineering University of.
Distributed Systems CS Project 1: File Storage and Access Kit (FileStack) Recitation 1, Aug 29, 2013 Dania Abed Rabbou and Mohammad Hammoud.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Network Programming. These days almost all devices.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit9: Internet programming 1.
Object-Orientated Analysis, Design and Programming
Tiny http client and server
WWW and HTTP King Fahd University of Petroleum & Minerals
Web Development Web Servers.
Computing with C# and the .NET Framework
NETWORK PROGRAMMING CNET 441
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
Sockets and URLs 17-Sep-18.
Sockets and URLs 13-Nov-18.
Clients and Servers 19-Nov-18.
Clients and Servers 1-Dec-18.
Sockets and URLs 3-Dec-18.
Server-side Programming CSE 333 Summer 2018
HTTP Hypertext Transfer Protocol
Clients and Servers 19-Jul-19.
Clients and Servers 13-Sep-19.
Presentation transcript:

Sockets For Servers Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University

Contents The ServerSocket class Examples

Server Socket A socket is a connection between two hosts Client connects to a Server and requests services from the server Servers are like receptionists who sit by the phone and wait for incoming call. Servers don’t know in advance who will call Java uses ServerSocket for servers

ServerSocket Basic life cycle of a server: – A new ServerSocket is created on a particular port using a ServerSocket() constructor – The ServerSocket linstens for incoming connection on the port (method accept() blocks until a client attempt to make a connect) – Server accepts a connection and returns a Socket objects connecting the client and the server – Using Socket’s getInputStream() and getOutputStream for sending to and receiving data from the client – The client, the server or both close the connection

ServerSocket ServerSocket public ServerSocket(int port) –Creates a server socket on a specified port. –A port of 0 creates a socket on any free port. –The maximum queue length for incoming connection indications (a request to connect) is set to 50. –If a connection indication arrives when the queue is full, the connection is refused.

ServerSocket public ServerSocket(int port, int backlog) –Creates a server socket and binds it to the specified local port number, with the specified backlog. –A port number of 0 creates a socket on any free port. –The maximum queue length for incoming connection indications (a request to connect) is set to the backlog parameter. –If a connection indication arrives when the queue is full, the connection is refused.

ServerSocket public ServerSocket(int port, int backlog, InetAddress bindAddr) –Create a server with the specified port, listen backlog, and local IP address to bind to. –The bindAddr argument can be used on a multi- homed host for a ServerSocket that will only accept connect requests to one of its addresses. –If bindAddr is null, it will default accepting connections on any/all local addresses. –The port must be between 0 and 65535, inclusive.

ServerSocket Example Example 11-1 LocalPortScan on page 353 List all the services for this machine Output from Win 2000: There is a server on port 135. There is a server on port 139. There is a server on port 445. There is a server on port There is a server on port There is a server on port There is a server on port There is a server on port There is a server on port There is a server on port 8888.

ServerSocket public Socket accept() –Listens for a connection to be made to this socket and accepts it. –The method blocks until a connection is made. –A new Socket s is created and, if there is a security manager, the security manager's checkAccept method is called with s.getInetAddress().getHostAddress() and s.getPort() as its arguments to ensure the operation is allowed. –This could result in a SecurityException. –Returns:the new Socket

ServerSocket Example 11-2 (Daytime Server) on page 357 No new thread is created for incoming call Current date is returned

ServerSocket Information public int getLocalPort() –Returns the port on which this socket is listening. public InetAddress getInetAddress() – Returns the local address of this server socket. – null if the socket is not yet connected. Example 11-4 RandomPort on page 362

Closing the ServerSocket public void close() –Closes this socket. Example for (int port = 1; port <= 65535; port++) { try { ServerSocket server = new ServerSocket(port); server.close(); } catch (IOException e) { System.out.println(“Server on port " + port + "."); } // end try } // end for

ServerSocket Options Accept will wait for an incoming connection for SO_TIMEOUT milliseconds. public void setSoTimeout(int timeout) –With this option set to a non-zero timeout, a call to accept() for this ServerSocket will block for only this amount of time. –If the timeout expires, a java.io.InterruptedIOException is raised –The option must be enabled prior to entering the blocking operation to have effect. –A timeout of zero is interpreted as an infinite timeout.

ServerSocket Options public int getSoTimeout() –Retrive setting for SO_TIMEOUT. –0 returns implies that the option is disabled (i.e., timeout of infinity). Examples in page 363

Client Test Example 11-5 on page 365 InputThread reads data from IE OuputThread sends data to IE

Single File Server Page 370 InputThread and OutputThread are executed in parallel. Can send a file to say IE or Netscape

Redirector Redirector redirects users from one web site to another See Example Try telnet –type GET / HTTP 1.0 (get index.html) –response: HTTP found ….. java Redirector –Redirect all http requests to

Redirector Ask Browser to redirect the request to newSite out.write("HTTP/ FOUND\r\n"); -- tell client to expect to be redirected out.write("Date: " + now + "\r\n"); -- optional (give current time of server) out.write("Server: Redirector 1.0\r\n"); -- Optional (version of the server) out.write("Location: " + newSite + theFile + "\r\n"); -- redirect to newSite

Redirector Note that some browser does not support redirection (OK for IE 5.0 and up and Netscape 4.7 and up) –Print the website is moved to newSite message. –See page 378 ( Document moved ….) –You may telnet to request redirector service Can be used to –firewall and –load balance control Thread pool provides better performance

JHTTP JHTTP: Full-blown HTTP server JHTTP can serve an entire document tree –Images –Applets –HTML and text files JHTTP uses thread pool to serve request –Threads are created when the server is started –If there is no request, thread are put to sleep (wait) –A request from a client will wake up all threads in the thread pool for service (notifyAll)

JHTTP When the thread is serving the request, it is just like a simple file transfer. –JHTTP thread: check (parse) the request and send the response –JHTTP thread: close the connection and go to sleep if there is no more request to be service

JHTTP JHTTP is functional but still rather simple A few features that can be added –A server administration interface –Support CGI programs and/or Java Servlet API –Support for other request methods such as POST, HEAD, and PUT –Server-side includes and/or Java server page – …

JHTTP Performance Issues –Use Just-in-time compiler such as Hotspot 2x ~ 10x –Smart caching Use Hashtable Use low-priority thread to update the cache