Networking Code CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.

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.
Björn Landfeldt School of Information Technologies NETS3303 Network Programming Intro.
Network Read/Write. Review of Streams and Files java.io package InputStream and OutputStream classes for binary bytes Reader and Writer classes for characters.
Programming Applets How do Applets work ? This is an HTML page This is the applet’s code It has a link to an applet.
Network Programming CS3250. References Core Java, Vol. II, Chapter 3. Book examples are available from
System Programming Practical session 10 Java sockets.
Client/Server example. Server import java.io.*; import java.net.*; import java.util.*; public class PrimeServer { private ServerSocket sSoc; public static.
Software Engineering Recitation 2 Suhit Gupta. Today we will be covering… XML II Sockets, Server – Client relationships, Servers capable of handling multiple.
28-Jun-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
Socket Communication Sockets provide an abstraction of two-point communication The two sides only read/write without concern for how data is translated.
1 Fall 2005 Socket Programming Qutaibah Malluhi Computer Science and Engineering Qatar University.
15-Jul-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
CSE 341, S. Tanimoto Java networking- 1 Java Networking Motivation Network Layers Using Sockets A Tiny Server Applets URLs Downloading Images, MediaTracker.
Web Services CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Performance measurements for inter-process communication.
Greg Jernegan Brandon Simmons. The Beginning…  The problem Huge demand for internet enabled applications and programs that communicate over a network.
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 12 Communicating over.
Methods CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 11.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Generics CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
CORBA – Command Line CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
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 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
OBJECT ORIENTED PROGRAMMING B.TECH II YR II SEMESTER(TERM 08-09) UNIT 8 PPT SLIDES TEXT BOOKS: 1. Java: the complete reference, 7th editon, Herbert schildt,
Web Design & Development 1 Lec - 21 Umair Javed. Web Design & Development 2 Socket Programming.
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.
File IO Basics By Dan Fleck Coming up: Data Streams.
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
CORBA – Eclipse CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Computer Networks & PROTOCOLS (CSI 4118) FALL 2005 Professor Robert L. Probert.
Java Server Programming Web Interface for Java Programs.
Concurrent Computing CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Serialization CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
Semaphores CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
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.
Networking with JavaN-1 Outline Client-Server Example Steps required on the server side Steps required on the client side.
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.
Li Tak Sing COMPS311F. Case study: a multithreaded chat server The source contains 3 files: ChatServer //the chat server ChatThread //the thread on the.
Liang, Oreilly, Herbert Schildt, Joseph O’Neil, Simon Roberts, IBM Corp Advanced Java Programming CSE 7345/5345/ NTU 531 Multithreaded/Sockets/Server Welcome.
Network Programming. These days almost all devices.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Reading Parameters CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit9: Internet programming 1.
SOCKET PROGRAMMING.
Java 13. Networking public class SumTest {
Echo Networking COMP
Networking Serialization
CSE 341, S. Tanimoto Java networking-
Socket Programming Cal Poly Pomona Young CS380.
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
Clients and Servers 19-Nov-18.
Clients and Servers 1-Dec-18.
Clients and Servers 19-Jul-19.
CS18000: Problem Solving and Object-Oriented Programming
Clients and Servers 13-Sep-19.
Presentation transcript:

Networking Code CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L

Outline USC CSCI 201L2/11 ▪S▪Server Networking ▪C▪Client Networking ▪P▪Program

Server Software ▪A server application is only able to serve requests that are addressed to the computer on which the server application is running ›A server program cannot listen to a port on another physical server ▪So, the only data the server application needs is the port on which to listen ›The ServerSocket constructor only takes a port as a parameter ▪Multiple networked applications can be running on the same computer as long as they are all using different ports USC CSCI 201L3/11 Server Networking

Multi-Threading with Networking ▪Multi-threading is usually necessary with networking since there are two things that often are done at the same time ›The ability to send data ›The ability to receive data ▪If sending and receiving are not performed in series, multi-threading will be needed ›Some applications may only need one program to send data then wait for a response – that would not require multi-threading USC CSCI 201L4/11 Server Networking

Server Networking Example (no multi-threading) 1 import java.io.BufferedReader; 2 import java.io.IOException; 3 import java.io.InputStreamReader; 4 import java.io.PrintWriter; 5 import java.net.ServerSocket; 6 import java.net.Socket; 7 8 public class NetworkingServer { 9 10 public NetworkingServer() { 11 try { 12 System.out.println("Starting Server"); 13 ServerSocket ss = new ServerSocket(6789); 14 Socket s = ss.accept(); 15 BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); 16 PrintWriter pw = new PrintWriter(s.getOutputStream()); String line = br.readLine(); 19 System.out.println("Line Received: " + line); 20 String str = "CSCI 201"; 21 System.out.println("Sending: " + str); 22 pw.println(str); 23 pw.flush(); 24 pw.close(); 25 br.close(); 26 s.close(); 27 ss.close(); 28 } catch (IOException ioe) { 29 System.out.println("IOE: " + ioe.getMessage()); 30 } 31 } 32 public static void main(String [] args) { 33 new NetworkingServer(); 34 } 35 } USC CSCI 201L5/11 Server Networking

Flushing ▪Operating systems try to optimize networking similar to how they optimize file I/O ▪A buffer exists where data is written into before sending along the socket ▪The buffer will not be transmitted over the network until it fills up unless we explicitly flush the data ▪Never forget to flush! USC CSCI 201L6/11 Server Networking

Outline USC CSCI 201L7/11 ▪S▪Server Networking ▪C▪Client Networking ▪P▪Program

Client Software ▪A client application is able to connect to any server application to which it has access, whether running on the same computer as the client or a different computer ▪The client application needs both the IP address of the server and the port on which the server application with which it wants to communicate is listening ›Remember that multiple server applications can be running on the same computer as long as they are listening on different ports ▪A Socket is the combination of the IP address and port number needed by the client USC CSCI 201L8/11 Client Networking

Client Networking Example (no multi-threading) 1 import java.io.BufferedReader; 2 import java.io.IOException; 3 import java.io.InputStreamReader; 4 import java.io.PrintWriter; 5 import java.net.Socket; 6 7 public class NetworkingClient { 8 9 public NetworkingClient() { 10 try { 11 System.out.println("Starting Client"); 12 Socket s = new Socket("localhost", 6789); 13 BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); 14 PrintWriter pw = new PrintWriter(s.getOutputStream()); String str = "Line being sent"; 17 System.out.println("Sending: " + str); 18 pw.println(str); 19 pw.flush(); 20 String line = br.readLine(); 21 System.out.println("Line Received: " + line); 22 pw.close(); 23 br.close(); 24 s.close(); 25 } catch (IOException ioe) { 26 System.out.println("IOE: " + ioe.getMessage()); 27 } 28 } 29 public static void main(String [] args) { 30 new NetworkingClient(); 31 } 32 } USC CSCI 201L9/11 Client Networking

Outline USC CSCI 201L10/11 ▪S▪Server Networking ▪C▪Client Networking ▪P▪Program

Program ▪Write a multi-threaded chat program that allows multiple clients to communicate with each other in an asynchronous manner. The clients should communicate with a server program. USC CSCI 201L11/11 Program C:>java ChatClient localhost 6789 hello Them: how are you? fine, and you? Them: good, thanks C:>java ChatClient localhost 6789 Them: hello how are you? Them: fine, and you? good, thanks