Socket Communication Sockets provide an abstraction of two-point communication The two sides only read/write without concern for how data is translated.

Slides:



Advertisements
Similar presentations
Network Programming and Java Sockets
Advertisements

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.
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.
© Amir Kirsh Java Networking Written by Amir Kirsh, Edited by Liron Blecher.
Prepared By: Eng. Ola M. Abd El-Latif May/2010.  In this Lab we will answer the most frequently asked questions about programming sockets in Java. 
1 Java Networking – Part I CS , Spring 2008/9.
Network Programming CS3250. References Core Java, Vol. II, Chapter 3. Book examples are available from
Java Networking -- Socket Server socket class: ServerSocket wait for requests from clients. after a request is received, a client socket is generated.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L22 (Chapter 25) Networking.
Java Socket Programming and Java RMI CS Recitation 1, Sep 8, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud.
1 Fall 2005 Socket Programming Qutaibah Malluhi Computer Science and Engineering Qatar University.
Network/Socket Programming in Java Rajkumar Buyya.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
Socket Programming in Java -First Step of Network Programming-
Greg Jernegan Brandon Simmons. The Beginning…  The problem Huge demand for internet enabled applications and programs that communicate over a network.
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.
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.
SOCKET PROGRAMMING. Client/Server Communication At a basic level, network-based systems consist of a server, client, and a media for communication as.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
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.
DBI Representation and Management of Data on the Internet.
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
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
© Amir Kirsh Java Networking Written by Amir Kirsh.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
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.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
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.
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
Networking Terminology: ISP (Internet service provider) – dialup, dsl, cable LAN (local area network) IP (internet protocol) address, eg
Network Programming All networked computers have an IP Address – Unique – In the form of xxx.xxx.xxx.xxx ( ) – 32 bits = ~4 billion possibilities.
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
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.
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-
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
CSE 501N Fall ‘09 22: Introduction to Networking November Nick Leidenfrost.
Network Programming: Servers. Agenda l Steps for creating a server Create a ServerSocket object Create a Socket object from ServerSocket Create an input.
Network Programming with Java java.net.InetAddress: public static void main(String[] args) throws UnknownHostException { InetAddress localAddress = InetAddress.getLocalHost();
1 CSCD 330 Network Programming Winter 2016 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection.
Java Networking I IS Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.
Networking OSI (Open Systems Interconnection) model of computer networking, seven layers (the Application, Presentation, Session, Transport, Network, Data.
Li Tak Sing COMPS311F. Case study: a multithreaded chat server The source contains 3 files: ChatServer //the chat server ChatThread //the thread on the.
SOCKET PROGRAMMING WITH JAVA By Collin Donaldson.
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
Lecture 21 Sockets 1 (Not in D&D) Date.
Clients and Servers 19-Nov-18.
Clients and Servers 1-Dec-18.
Chapter 2: Application layer
Clients and Servers 19-Jul-19.
Clients and Servers 13-Sep-19.
Presentation transcript:

Socket Communication Sockets provide an abstraction of two-point communication The two sides only read/write without concern for how data is translated (encoded) and transmitted Socket is a pair (address, port) address: www.google.com, turing.cc.gettysburg.edu, 135.24.78.123 port: 21 (ftp), 22 (ssh), 23 (telnet), 80 (http), 101 (pop mail)

Socket Communication web server listen on port 80 server (turing.cc.gettysburg.edu) client (135.24.78.123) web server listen on port 80

Socket Communication web server listen on port 80 server (turing.cc.gettysburg.edu) request web page turing.cc…:80 client (135.24.78.123) socket 135.24.78.123:1234 web server listen on port 80

Socket Communication web server listen on port 80 server (turing.cc.gettysburg.edu) request web page turing.cc…:80 client (135.24.78.123) socket 135.24.78.123:1234 accept request socket tuing.cc…..:5789 web server listen on port 80

Socket Communication web server listen on port 80 server (turing.cc.gettysburg.edu) client (135.24.78.123) socket tuing.cc…..:5789 socket 135.24.78.123:1234 web server listen on port 80

Socket Communication web server listen on port 80 server (turing.cc.gettysburg.edu) client (135.24.78.123) socket tuing.cc…..:5789 socket 135.24.78.123:1234 request web page turing.cc…:80 client (135.24.78.567) web server listen on port 80 socket 135.24.78.567:1024

Socket Communication web server listen on port 80 server (turing.cc.gettysburg.edu) client (135.24.78.123) socket tuing.cc…..:5789 socket 135.24.78.123:1234 request web page turing.cc…:80 client (135.24.78.567) web server listen on port 80 socket 135.24.78.567:1024 accept request socket tuing.cc…..:8019

Socket Communication web server listen on port 80 server (turing.cc.gettysburg.edu) client (135.24.78.123) socket tuing.cc…..:5789 socket 135.24.78.123:1234 client (135.24.78.567) web server listen on port 80 socket tuing.cc…..:8019 socket 135.24.78.567:1024

Multi-Threaded Server client (135.24.78.123) request web page turing.cc…:80 server socket (addr : port) turing.cc.gettysburg.edu : 80 socket (addr : port) 135.24.78.123 : 1234 socket tuing.cc…..:5789 request web page turing.cc…:80 client (128.4.99.100) socket (addr : port) 128.4.99.100 : 1234 socket tuing.cc…..:8019 listening thread (wait for connect)

Simple Server (one client) Open the Server Socket ServerSocket server = new ServerSocket(5678); Wait for Client Request Socket connection = server.accept(); Create Streams for Communication OutputStream os = connection.getOutputStream(); DataOutputStream output = new DataOutputStream (os); Carry Out Communication output.writeUTF("Hi there"); Close Communication output.close(); os.close(); connection.close(); server.close();

Simple Server (one client) public static void main(String[] args) { // Register service on port 1234 ServerSocket server = new ServerSocket(1234); // Wait and accept a connection Socket connection = server.accept(); // Get a communication stream associated with the socket OutputStream os = connection.getOutputStream(); DataOutputStream output = new DataOutputStream(os); // Send a string! output.writeUTF("Hi there"); // Close the connection output.close(); os.close(); connection.close(); server.close(); }

Multi-Threaded Server Open the Server Socket ServerSocket server = new ServerSocket(5678); Wait for Client Request Socket connection = server.accept(); Spawn a client thread (give the connection) Create Streams for Communication OutputStream os = connection.getOutputStream(); DataOutputStream output = new DataOutputStream (os); Carry Out Communication output.writeUTF("Hi there"); Close Communication output.close(); os.close(); connection.close(); server.close();

Simple Server (one client) public static void main(String[] args) { // Register service on port 1234 ServerSocket server = new ServerSocket(1234); // Wait and accept a connection while (true) { Socket connection = server.accept(); Thread client = new ClientThread(connection); } Code for ClientThread: // get communication channel associated with the socket OutputStream os = connection.getOutputStream(); DataOutputStream output = new DataOutputStream (os); output.writeUTF("Hi there"); // communicate os.close(); output.close(); // close resources connection.close();

Simple Client MIDlet (no change) Create a Socket Connection SocketConnection connection = (SocketConnection)Connector.open("socket://gbcs10:5678"); Create Streams for Communication InputStream is = connection.openInputStream(); DataInputStream input = new DataInputStream(is); Carry Out Communication String data = new String (input.readUTF()); Close Communication is.close(); input.close(); connection.close();

Simple Client MIDlet (no change) try { SocketConnection connection = (SocketConnection) Connector.open("socket://gbcs10:1234"); InputStream is = connection.openInputStream(); DataInputStream input = new DataInputStream(is); String data = new String (input.readUTF()); is.close(); input.close(); connection.close(); } catch (. . .) {

Synchronous Multi-Threaded Chat Server Lab Exercise Synchronous Multi-Threaded Chat Server