Lab 6: Introduction to Sockets (Web Programming – Part 1) Reference: Head First Java (2 nd Edition) by Kathy Sierra & Bert Bates.

Slides:



Advertisements
Similar presentations
Discussion Section Week 3 EE122: Introduction to Communication Networks Fall 2006.
Advertisements

Basic Socket Programming with Java. What is a socket?  Generally refers to a stream connecting processes running in different address spaces (across.
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 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Network Programming CS3250. References Core Java, Vol. II, Chapter 3. Book examples are available from
System Programming Practical session 10 Java sockets.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L23 (Chapter 25) Networking.
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.
Client-Server Communication Sockets Remote Procedure Calls Remote Method Invocation (Java)
Welcome to CIS 235 Computer Networks Fall, 2007 Prof Peterson.
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.
Networking with Java CSc 335 Object-Oriented Programming and Design Spring 2009.
1 Network Programming Introduction zBased on Classes in the java.net package zLecture focuses on: yTCP and UDP yNetwork programming basics yIdentifying.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
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 in Java -First Step of Network Programming-
Misc. Java Alittle more network programming & Using jar files to share your work.
Socket Lab Info. Computer Network. Requirement Use TCP socket to implement a pair of programs, containing a server and a client. The server program shall.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 12 Communicating over.
Introduction to Interprocess communication SE-2811 Dr. Mark L. Hornick 1.
Cli/Serv.: Chat/121 Client/Server Distributed Systems v Objectives –discuss a client/server based chat system –mention two other ways of chatting.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
Data Streams David Meredith Source Chapter 19 of – Shiffman, D. (2008). Learning Processing. Morgan Kaufmann, Burlington, MA. ISBN:
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 11.
Establishing communication with Envirobat using TCP/IP Presented by Apourva Parthasarathy Date : 18/06/13.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
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.
© Lethbridge/Laganière 2005 Chap. 3: Basing Development on Reusable Technology The Client-Server Architecture A distributed system is a system in.
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.
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.
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,
Java Sockets Tutorial Rahul Malik Nov 12, 2005.
CSC 480 Software Engineering Socket. What is Socket? A socket is one end-point of a two-way communication link between two programs running on the network.
Field Trip #25 Creating a Client/Server By Keith Lynn.
Socket Programming Introduction. Socket Definition A network socket is one endpoint in a two-way communication flow between two programs running over.
Java Server Programming Web Interface for Java Programs.
1 CSCD 330 Network Programming Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 9 Client-Server Programming.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
Prepared by Dr. Jiying Zhao University of Ottawa Canada.
1 COMP 431 Internet Services & Protocols Client/Server Computing & Socket Programming Jasleen Kaur February 2, 2016.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Socket Programming in Java -First Step of Network Programming-
Networking with JavaN-1 Outline Client-Server Example Steps required on the server side Steps required on the client side.
Java Networking I IS Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.
Java’s networking capabilities are declared by the classes and interfaces of package java.net, through which Java offers stream-based communications that.
Liang, Oreilly, Herbert Schildt, Joseph O’Neil, Simon Roberts, IBM Corp Advanced Java Programming CSE 7345/5345/ NTU 531 Multithreaded/Sockets/Server Welcome.
LAN Chat server BY: VIPUL GUPTA VIKESH SINGH SUKHDEEP SINGH.
The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem.
The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem.
The Chat Problem.
Internet Socket Programing
Client-Server Communication
CSE 341, S. Tanimoto Java networking-
MCA – 405 Elective –I (A) Java Programming & Technology
Beyond HTTP Up to this point we have been dealing with software tools that run on browsers and communicate to a server that generates files that can be.
Socket Programming Cal Poly Pomona Young CS380.
Socket Programming in Java
EE 422C Socket Programming
Introduction to Client/Server Design
Software Engineering for Internet Applications
CSCD 330 Network Programming
Software Engineering and Architecture
Presentation transcript:

Lab 6: Introduction to Sockets (Web Programming – Part 1) Reference: Head First Java (2 nd Edition) by Kathy Sierra & Bert Bates

Connecting with the outside world Your Java program can reach out and communicate with a program on another machine. All the low-level networking details are taken care of by classes in the java.net library. One of Java’s big benefits is that sending and receiving data over a network is just I/O with a slightly different connection stream at the end of the chain. We are going to learn how to connect to the outside world by creating client and server sockets.

What is a Socket? To connect to another machine, we need a Socket connection. A Socket is an object that represents a network connection between two machines. A connection is a relationship between two machines, where two pieces of software know about each other and, most importantly, they know how to communicate with each other. To make a Socket connection, you need to know two things about the server first: 1. Who it is (IP Address). 2. Which port it’s running on (Port number).

Getting the client to work 1. Client connects to the server by establishing a Socket connection. 2. Client sends a message to the server. 3. Client gets a message from the server.

Reading from a Socket To read data from a Socket, we use a BufferedReader. 1. Make a Socket connection to the Server. Socket gameSocket = new Socket(IPaddress, PortNumber); 2. Make an InputStreamReader chained to the Socket’s low-level (connection) input stream. InputStreamReader stream = new InputStreamReader(gameSocket.getInputStream()); 3. Make the BufferedReader and read! BufferedReader = new BufferedReader(stream); String message = reader.readLine();

Writing to a Socket To write data to a Socket, we use a PrintWriter. 1. Make a Socket connection to the Server. Socket gameSocket = new Socket(IPaddress, PortNumber); 2. Make a PrintWriter chained to the Socket’s low-level (connection) output stream. PrintWriter writer = new PrintWriter(gameSocket.getInputStream()); 3. Write (print) something! writer.println(“message to send”);