Network Programming CS3250. References Core Java, Vol. II, Chapter 3. Book examples are available from

Slides:



Advertisements
Similar presentations
Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
Advertisements

Lecture 2b Sockets Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Network Read/Write. Review of Streams and Files java.io package InputStream and OutputStream classes for binary bytes Reader and Writer classes for characters.
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.
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.
WECPP1 Java networking Jim Briggs based on notes by Amanda Peart based on Bell & Parr's bonus chapter
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
System Programming Practical session 10 Java sockets.
A Chat Server DBI – Representation and Management of Data on the Internet.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L22 (Chapter 25) Networking.
© 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.
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.
Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers.
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.
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.
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 12 Communicating over.
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
COMP201 Java Programming Part III: Advanced Features Topic 13: Networking Volume II,Chapter 3.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 21.
Lab 6: Introduction to Sockets (Web Programming – Part 1) Reference: Head First Java (2 nd Edition) by Kathy Sierra & Bert Bates.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
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
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
1 Rick Mercer Multi Threaded Chat Server. 2 Client – Server with Socket Connections We've seen how to establish a connection with 1 client Review a simple.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
© 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.
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
Web Design & Development 1 Lec - 21 Umair Javed. Web Design & Development 2 Socket Programming.
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.
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.
Introduction to Sockets “A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port.
 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.
Field Trip #25 Creating a Client/Server By Keith Lynn.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
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 ( 李德成 )
CSE 501N Fall ‘09 22: Introduction to Networking November Nick Leidenfrost.
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.
Java Networking I IS Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.
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
The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem.
The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit9: Internet programming 1.
SOCKET PROGRAMMING.
Java 13. Networking public class SumTest {
Object-Orientated Analysis, Design and Programming
Echo Networking COMP
Networking COMP
Socket Programming Cal Poly Pomona Young CS380.
Clients and Servers 19-Nov-18.
Clients and Servers 1-Dec-18.
Software Engineering and Architecture
Clients and Servers 19-Jul-19.
CS18000: Problem Solving and Object-Oriented Programming
Clients and Servers 13-Sep-19.
Presentation transcript:

Network Programming CS3250

References Core Java, Vol. II, Chapter 3. Book examples are available from Web site for Practical TCP/IP Sockets in Java by Kenneth L. Calvert and Michael J. Donahoo. Slides and sample code: JavaSockets/ JavaSockets/ The Java Tutorial: working/index.html working/index.html

The Server Server The server starts running first and waits for clients to connect. ServerSocket s = new ServerSocket(8189); Socket incoming = s.accept(); Port number This socket is only used to get new connections to clients. The server does not read from or write to this socket. from EchoServer.java, Core Java Vol. II, Ch. 3, pp (8 th ed.)

Accepting Connections Server The server starts running first and waits for clients to connect. ServerSocket s = new ServerSocket(8189); Socket incoming = s.accept(); Each time a client connects, the server gets a new socket which it uses only to communicate with that client. from EchoServer.java, Core Java Vol. II, Ch. 3, pp (8 th ed.) Client programs do not use the ServerSocket class or call accept.

The Client Server Client All transactions are initiated by clients. The client must know the name (or IP address) and port number of the server. Socket s = new Socket("localhost", 8189);

Input and Output Streams Server Client The client gets the input and output streams from the socket to receive and send to the server. Socket s = new Socket("localhost", 8189); OutputStream outStream = s.getOutputStream(); PrintWriter out = new PrinterWriter (outStream, true); InputStream inStream = s.getInputStream(); Scanner in = new Scanner(inStream);

Sending to the Server Server Client The client uses the output stream to send a request to the server. Request out.println("connect Gimli");

Receiving a Reply Server Client The client uses the input stream to receive replies from the server. Reply String reply = in.nextLine(); The nextLine method will block until the server sends a reply. If the program only has one thread, the whole program will be blocked, which is usually not good.

Using Threads Server Client Messages from the server Messages to the server Thread 1 Thread 2 User I/O