Trådad Echo server public class ThreadedEchoServer extends Thread { Socket con; public static void main(String[] args) {... try { ServerSocket ss = new.

Slides:



Advertisements
Similar presentations
CS Network Programming CS 3331 Fall CS 3331 Outline Socket programming Remote method invocation (RMI)
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Network Programming and Java Sockets
Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.
SOCKET PROGRAMMING WITH MOBILE SOCKET CLIENT DEARTMENT OF COMPUTER SCIENCE IOWA STATE UNIVERSITY.
ServerSocket H. Fauconnier 1-1 M2-Internet Java. Principe 1. Création dun ServerSocket par constructeur 2. Association (bind) de la socket à une adresse.
Inter-Process Communication: Network Programming using TCP Java Sockets Dr. Rajkumar Buyya Cloud Computing and Distributed Systems (CLOUDS) Laboratory.
1 Network Programming and Java Sockets Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software.
Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
Distribuerade system Java Sockets RMI Etc.. Vad är distribuerade system Distr system är enkla att förstå –Distribuera last –Centrala funktioner på samma.
Sockets for Clients Socket Basics  Connect to a remote machine  Send data  Receive data  Close a connection  Bind to a port 
Using TCP sockets in Java Created by M Bateman, A Ruddle & C Allison As part of the TCP View project.
Network Read/Write. Review of Streams and Files java.io package InputStream and OutputStream classes for binary bytes Reader and Writer classes for characters.
Java Threads A tool for concurrency. OS schedules processes Ready Running 200 Blocked A process loses the CPU and another.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
WECPP1 Java networking Jim Briggs based on notes by Amanda Peart based on Bell & Parr's bonus chapter
1 Networking with Java 2: The Server Side. 2 Some Terms Mentioned Last Week TCP -Relatively slow but enables reliable byte-stream transmission UDP -Fast.
Java Networking -- Socket Server socket class: ServerSocket wait for requests from clients. after a request is received, a client socket is generated.
Client/Server In Java An Introduction to TCP/IP and Sockets.
Socket Communication Sockets provide an abstraction of two-point communication The two sides only read/write without concern for how data is translated.
Networking with Java CSc 335 Object-Oriented Programming and Design Spring 2009.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
19-Aug-15 About the Chat program. 2 Constraints You can't have two programs (or two copies of the same program) listen to the same port on the same machine.
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
Socket programming 1. getByName import java.net.*; public class GetHostName { public static void main (String args[]) { String host = "
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
UDP vs TCP UDP Low-level, connectionless No reliability guarantee TCP Connection-oriented Not as efficient as UDP.
Socket Programming in Java CS587x Lecture 4 Department of Computer Science Iowa State University.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
© Amir Kirsh Java Networking Written by Amir Kirsh.
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.
Java Sockets Programming
Introduction to Socket Programming in Android Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 22.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Networking and Concurrency COMP.
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
Servers and Sockets Carol Wolf Computer Science. Java network programming classes  SocketImpl – abstract class and superclass of the rest  Four fields:
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.
Java Programming II Java Network (I) Java Programming II.
Java Server Sockets ServerSocket : Object to listen for client connection requests Throws IOException accept() method to take the client connection. Returns.
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 ( 李德成 )
Network Programming: Servers. Agenda l Steps for creating a server Create a ServerSocket object Create a Socket object from ServerSocket Create an input.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Java 13. Networking public class SumTest {
Echo Networking COMP
Threads in Java Two ways to start a thread
CSE 341, S. Tanimoto Java networking-
Network Programming Introduction
Networking with Java 2.
An Introduction to TCP/IP and Sockets
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
Java Network Programming
Clients and Servers 19-Nov-18.
Clients and Servers 1-Dec-18.
class PrintOnetoTen { public static void main(String args[]) {
Clients and Servers 19-Jul-19.
CS18000: Problem Solving and Object-Oriented Programming
Clients and Servers 13-Sep-19.
Presentation transcript:

Trådad Echo server public class ThreadedEchoServer extends Thread { Socket con; public static void main(String[] args) {... try { ServerSocket ss = new ServerSocket(port); while (true) { try { Socket s = ss.accept(); ThreadedEchoServer tes = new ThreadedEchoServer(s); tes.start(); } catch() {}... } } catch() {}...

Trådad Echo server (forts) public ThreadedEchoServer(Socket s) { con = s; } public void run() { try { System.out.println("New echo server threaded"); OutputStream os = con.getOutputStream(); InputStream is = con.getInputStream(); while (true) { int n = is.read(); if (n == -1) break; os.write(n); os.flush(); } } catch(){}...

Trådar och server’s Kostar tid att skapa en ny tråd varje gång man får en uppkoppling –Lösning: Köa socket anropen och lägg upp en pool med trådar som kan användas av klienter

PoolEchoServer public class PoolEchoServer extends Thread { public final static int defaultPort = 2347; ServerSocket theServer; static int num_threads = 10; public static void main(String[] args) { int port = defaultPort;... ServerSocket ss = new ServerSocket(port); for (int i = 0; i < num_threads; i++) { PoolEchoServer pes = new PoolEchoServer(ss); pes.start(); }... }

PoolEchoServer public PoolEchoServer(ServerSocket ss) { theServer = ss; } public void run() { while (true) { try { Socket s = theServer.accept(); System.out.println("New echo server threaded"); OutputStream os = s.getOutputStream(); InputStream is = s.getInputStream(); while (true) { int n = is.read(); if (n == -1) break; os.write(n); os.flush(); } // end while } // end try catch (IOException e) { } } // end while } // end run