Practicum: - Client-Server Computing in Java 15-211 Fundamental Data Structures and Algorithms Peter Lee April 8, 2004.

Slides:



Advertisements
Similar presentations
Using TCP sockets in Java Created by M Bateman, A Ruddle & C Allison As part of the TCP View project.
Advertisements

Socket Programming By Ratnakar Kamath. What Is a Socket? Server has a socket bound to a specific port number. Client makes a connection request. Server.
Network Programming Chapter 11 Lecture 6. Networks.
2: Application Layer 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
Socket Programming.
1 Creating a network app Write programs that  run on different end systems and  communicate over a network.  e.g., Web: Web server software communicates.
1 Java Networking – Part I CS , Spring 2008/9.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
CS3771 Today: network programming with sockets  Previous class: network structures, protocols  Next: network programming Sockets (low-level API) TODAY!
System Programming Practical session 10 Java sockets.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
Client/Server In Java An Introduction to TCP/IP and 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.
TCP Socket Programming CPSC 441 Department of Computer Science University of Calgary.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
CS-3013 & CS-502, Summer 2006 Network Input & Output1 CS-3013 & CS-502, Summer 2006.
1 Network Layers Application Transport Network Data-Link Physical bits.
Welcome to CIS 235 Computer Networks Fall, 2007 Prof Peterson.
An Introduction to Internetworking. Algorithm for client-server communication with UDP (connectionless) A SERVER A CLIENT Create a server-socket (listener)and.
2: Application Layer 1 Socket Programming Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley,
Chapter 26 Client Server Interaction Communication across a computer network requires a pair of application programs to cooperate. One application on one.
2: Application Layer 1 Socket Programming TCP and UDP.
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
CS 352-Socket Programming & Threads Dept. of Computer Science Rutgers University (Thanks,this slides taken from er06/
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
CS 3830 Day 11 Introduction : Application Layer 2 Server-client vs. P2P: example Client upload rate = u, F/u = 1 hour, u s = 10u, d min ≥ u s.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 21.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
Cli/Serv.: Chat/121 Client/Server Distributed Systems v Objectives –discuss a client/server based chat system –mention two other ways of chatting.
Winter 2002Suprakash Datta1 Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
-1- Georgia State UniversitySensorweb Research Laboratory CSC4220/6220 Computer Networks Dr. WenZhan Song Associate Professor, Computer Science.
1 CSCD 330 Network Programming Winter 2015 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Socket Programming Lee, Sooyong
Network Programming and Sockets CPSC 363 Computer Networks Ellen Walker Hiram College (Includes figures from Computer Networking by Kurose & Ross, © Addison.
Socket Programming Tutorial. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server 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.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
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.
© Lethbridge/Laganière 2005 Chap. 3: Basing Development on Reusable Technology The Client-Server Architecture A distributed system is a system in.
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 Socket programming. Socket programming with TCP.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/11) Java Sockets and Simple Networking Joel Adams and Jeremy Frens.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
2: Application Layer1 Socket programming Socket API Explicitly created, used, released by apps Client/server paradigm Two types of transport service via.
1 CSCD 330 Network Programming Spring 2014 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 7 Application.
Part 4: Network Applications Client-server interaction, example applications.
1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
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.
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.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 11 Omar Meqdadi Department of Computer Science and Software Engineering University.
Advance Computer Programming Networking Basics – explores the java.net package which provides support for networking. – Also Called “programming for the.
Network Programming. These days almost all devices.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Networking COMP
MCA – 405 Elective –I (A) Java Programming & Technology
Socket programming - Java
Socket Programming.
Socket Programming 2: Application Layer.
Presentation transcript:

Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Peter Lee April 8, 2004

Reminders  HW7 is out!  due on Wednesday, April 28, 11:59pm  Read:  Chapter 10  Next time:  Guest lecture by Andreas Nowatzyk (Deep Thought)

Recap: Learning to Play Games

Game playing strategies  Last time we were introduced to minimax search as an approach to two-player games  For interesting games, it is very important to prune the search tree  We saw the alpha/beta pruning technique could be very useful

AI  But the quality of the evaluation function and the search order is also of critical importance  So this leaves us with the question: How do we come up with a good evaluation function and a good search order?  These are fundamental questions in Artificial Intelligence

Learning  We can, of course, be as thoughtful and clever as possible, analyze the game carefully, and design an evaluation function accordingly  But this is often difficult  Another approach is to arrange for our game playing program to learn

Many approaches…  Indeed, machine learning is a very big and important topic in CS  take , , etc  many approaches, some of them highly mathematical or statistical

Samuels checkers program  An early 60’s checkers program by Samuels learned by playing games against good human players  It updated its evaluation function whenever it won a game, and ignored losing games  In time, it became the best checkers player in major tournaments

Learning from humans or computers?  While Samuel’s program was very successful, it also had some drawbacks  It would actually get worse when playing poor players  Humans play very slowly, and so this limited the pace of learning

State-of-the-art: Backgammon  Gerald Tesauro (IBM)  Wrote a program which became “overnight” the best player in the world  Not easy!

State-of-the-art: Backgammon  Learned the evaluation function by playing 1,500,000 games against itself  Temporal credit assignment using reinforcement learning  Used Neural Network to learn the evaluation function ab c d

State-of-the-art: Go  Average branching factor 360  Regular search methods go bust !  People use higher level strategies  Systems use vast knowledge bases of rules… some hope, but still play poorly  $2,000,000 for first program to defeat a top-level player

Today’s Topic: Intro to Distributed Computing Concepts

Distributed computing  Many applications involve coordinated computation by multiple host computers World-Wide Web Internet Chess Club Andrew File System services X Windows …

The client-server paradigm  Almost all modern distributed computing applications are organized around the client-server paradigm  Client  initiates communication  sends requests and receives responses  interacts with one (or a small number) of servers at a time  Server  waits and listens for incoming requests  receives requests and sends responses  interacts with many clients concurrently

Network communication  Network communication is organized into layers  hardware layer  network interface device, connected to a local area network, which in turn is connected to a (packet switched) Internet  protocol layer(s)  basic data transport mechanisms, providing addressing (eg, IP addresses), fragmention/reassembly, reliable transmission  application layer  client and server functionality

Hardware layer  Typically Ethernet-based  Data is transmitted in small packets  typically less than 1500 bytes  packets are easily lost, and often arrive in unpredictable order  Each packet contains routing information  A network device watches for packets that are addressed to itself, ignores the rest  Routers look for packets that are not addressed to local hosts, and forwards them to a non-local network router

Protocol layer  There are two main protocols used  both provide Internet addressing/routing  TCP  Transmission Control Protocol  connection (“session”) oriented  provides long data messages (via fragmentation and reassembly of packets)  provides reliable communication  UDP  Unreliable Datagram Protocol  not connection oriented  no transmission guarantees, but very lightweight and efficient

Application layer  The hardware and protocol layers are studied in  Here, we will focus on the application level  Most networking applications use a particular data structure, the socket  A socket provides a high-level abstract interface to a lower-level network protocol service  In Java, sockets are similar in some respects to input/output streams

Sockets  Sockets have a long history in network and operating system design  first appeared in BSD 4.1 Unix in 1981  Socket characteristics  applications explicitly create, use, and destroy sockets  distinction between client sockets and server sockets  different kinds of sockets, depending on the transport protocol (TCP vs UDP)

Sockets in Java  Java provides very good support for sockets in the java.net.* package  java.net.Socket  create: constructor methods (to create sockets)  I/O: getOutputStream(), getInputStream()  destroy: close()  java.net.ServerSocket  create: constructor methods  wait and listen: accept()  destroy: close()

Socket programming with TCP  Client must contact the server  server must first be waiting and listening  server must thus have created a socket that accepts client connection request  Client contacts server by:  creating its own client TCP socket  uses IP address and port number of server

Socket programming, cont’d  When client creates its socket, a TCP session with the server’s TCP is established  On the server side:  when contacted by the client, the server TCP creates a new socket for communication with the client  thus, each client session gets its own private socket on the server

Client-server interaction listenSocket = ServerSocket(port) connectionSocket = listenSocket.accept() read request(s) from connectionSocket write reply(s) to connectionSocket connectionSocket.close() clientSocket = Socket(hostid,port) send request(s) to clientSocket read reply(s) from clientSocket clientSocket.close() Server Client

Example: A Pig Latin Server

Example: Java client import java.io.*; import java.net.* public class Client { public static void main (String argv[]) throws Exception { BufferedReader user = new BufferedReader(…); Socket clientSocket = new Socket(“foo.cs.cmu.edu”, 6789); PrintWriter out = new PrintWriter( clientSocket.getOutputStream(),true); … create user input stream connect to the server create output stream

Java client, cont’d … BufferedReader in = new BufferedReader( new InputStreamReader( clientSocket.getInputStream())); String sentence = user.readLine(); out.println(sentence); String pigLatin = in.readLine(); System.out.println(“Server says:” + pigLatin); clientSocket.close(); create input stream send request to the server read reply from server release the connection

Example: Java server import java.io.*; import java.net.* public class Server { public static void main (String argv[]) throws Exception { ServerSocket listenSocket = new ServerSocket(6789); while (true) { Socket connectionSocket = listenSocket.accept(); BufferedReader in = new BufferedReader( new InputStreamReader( connectionSocket.getInputStream())); create listening socket wait for client contact create input stream on host foo.cs.cmu.edu:

Java server, cont’d PrintWriter out = new PrintWriter( connectionSocket.getOutputStream(),true); clientSentence = in.readLine(); String pigLatin = pigTranslate(clientSentence); out.println(pigLatin); connectionSocket.close(); } create output stream read request from client service the request send reply to client end of while loop; go back and wait for another request

Practical issue: cleaning up  Closing connections  It is important to close connections  usually a strict limit on the number of open connections  This means it is very important to handle exceptions, in case the socket creation or I/O fail  exception handler should close any open connections

Exception handling … try { Socket clientSocket = new Socket(“foo.cs.cmu.edu”, 6789); … } catch (UnknownHostException e) { System.err.println( “Couldn’t find the server host!”); } catch (IOException e) { System.err.println( “I/O error!”); } finally { try { if (clientSocket != null) { out.close(); in.close(); clientSocket.close(); } } catch (IOException e) { … } } this is always executed, no matter what

Practical issue: concurrency  The server usually must be designed to handle multiple clients concurrently  This means that the server should be set up so that the multiple copies of the main server loop can be running at the same time  Java provides a mechanism for such separate “threads” of control, in java.lang.Thread

Example: multithreaded server import java.io.*; import java.net.* public class Server extends Thread { ServerSocket listenSocket; public Server () { try { listenSocket = new ServerSocket(6789); } catch (IOException e) { … } this.start(); } … create listening socket when client contacts us, start a server loop thread for it on host foo.cs.cmu.edu:

Multithreaded server, cont’d … public void run() { try { while (true) { Socket connectionSocket = listenSocket.accept(); … run() is invoked by start(), after a new thread is created