 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/11) Java Sockets and Simple Networking Joel Adams and Jeremy Frens.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Network Programming and Java Sockets
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.
2: Application Layer1 Data Communication and Networks Lecture 12 Java Sockets November 30, 2006.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
System Programming Practical session 10 Java sockets.
Projekt współfinansowany przez Unię Europejską w ramach Europejskiego Funduszu Społecznego „Networking”
1 School of Computing Science Simon Fraser University CMPT 771/471: Internet Architecture and Protocols Socket Programming Instructor: Dr. Mohamed Hefeeda.
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.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
1 Network Layers Application Transport Network Data-Link Physical bits.
2: Application Layer 1 Socket Programming Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley,
1 Network Programming Introduction zBased on Classes in the java.net package zLecture focuses on: yTCP and UDP yNetwork programming basics yIdentifying.
2: Application Layer 1 Socket Programming TCP and UDP.
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
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.
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.
TCP/IP: Basics1 User Datagram Protocol (UDP) Another protocol at transport layer is UDP. It is Connectionless protocol i.e. no need to establish & terminate.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
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.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
Socket Programming Lee, Sooyong
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.
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.
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.
Java Socket programming. Socket programming with TCP.
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.
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.
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.
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.
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.
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.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
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.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 11 Omar Meqdadi Department of Computer Science and Software Engineering University.
Networking Mehdi Einali Advanced Programming in Java 1.
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
Network Programming Communication between processes Many approaches:
Object-Orientated Analysis, Design and Programming
Network Programming in Java CS 1111 Ryan Layer May 3, 2010
MCA – 405 Elective –I (A) Java Programming & Technology
Block 14 Group Communication (Multicast)
„Networking”.
Socket programming - Java
CSCD 330 Network Programming
Socket Programming.
CSCD 330 Network Programming
Presentation transcript:

 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/11) Java Sockets and Simple Networking Joel Adams and Jeremy Frens Calvin College

 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(2/11) The TCP/IP Stack TCP/IP is a layered protocol family: Hardware  Application layer protocols convert app. program data to/from messages FTPTELNETSMTP... messages  Transport layer protocols convert messages to/from packets. TCPUDP packets  The Internet layer protocol (IP) converts packets to/from IP datagrams IP datagrams  The Network interface layer protocol (X.25) converts IP datagrams to/from network’s frames to send/receive... X.25 frames TCP/IP Applications data

 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(3/11) host j host i TCP/IP app i TCP/IP app j Application Transport Internet Network Application Transport Internet Network network End-to-End Communication The stacks enable any two hosts to communicate in a point-to-point fashion. A TCP/IP network is a collection of communication links and hosts, with each host having a TCP/IP stack. Control info is also sent between specific layers... Each layer of the stack (at each end) performs its respective task. data messagepacketsdatagrams frames

 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(4/11) host j host i network The Client-Server Model Most TCP/IP applications use the client-server model, splitting a network application into two parts: Servers for specific services use well-known ports: echo7 daytime13 quote17 ftp-data20 ftp-cntl21 telnet23 smtp25 dns53 finger79  A client that contacts a server to access the service it offers: client app  An always-running server (or daemon) that provides a specific service: server app

 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(5/11) Sockets  To provide a service to clients, a server:  creates a socket using a given protocol (TCP or UDP) and port  waits for a client to send a request to the socket (blocking)  receives a request via the socket, processes it  sends any results back to the client via the socket  To request service from a server, a client:  creates a socket  uses it to send a request for service to a server  uses it to receive any results from the server Most TCP/IP applications communicate using an abstraction called a socket, that represents a communication endpoint. Sockets are the software infrastructure of TCP/IP networks.

 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(6/11) Java Sockets  ServerSocket is a class representing TCP server sockets,  Socket is a class representing TCP client sockets, and  DatagramSocket is a class representing UDP sockets, that provides send() and receive() methods by which clients and servers can send/receive DatagramPacket objects. Java provides separate classes to represent various kinds of sockets, including: Java also provides class InetAddress and other useful classes in its java.net package.

 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(7/11) TCP Echo Client A client for the echo service is easy to write... import java.net.*; // Socket import java.io.*; // BufferedReader, PrintWriter,... class EchoClient { public static void main(String [] args) { //... Omitted: Code to input echo server’s name and port try { BufferedReader keyboard = new BufferedReader( new InputStreamReader( System.in ) ); PrintWriter screen = new PrintWriter( new OutputStreamWriter( System.out ), true ); // … continued on next slide …

 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(8/11) TCP Echo Client (ii) //... continued from previous slide … Socket s = new Socket(InetAddress.getByName(remoteHost), remotePort); BufferedReader sin = new BufferedReader( new InputStreamReader( s.getInputStream() )); PrintWriter sout = new PrintWriter( new OutputStreamWriter( s.getOutputStream() ), true ); String lineFromUser = null, lineFromServer = null; for (;;) { lineFromUser = keyboard.readLine(); if ( lineFromUser.equals("quit") ) break; sout.println(lineFromUser); lineFromServer = sin.readLine(); screen.println(lineFromServer); } s.close(); } catch( Exception e ) { System.err.println(e); } } Note: This program does not follow the MVC pattern…

 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(9/11) TCP Echo Client A client using the MVC pattern is also easy to write... import java.net.*; // Socket import java.io.*; // BufferedReader, PrintWriter,... class EchoClient2 { public static void main(String [] args) { //... Omitted: Code to input echo server’s name and port try { BufferedReader keyboard = new BufferedReader( new InputStreamReader( System.in ) ); PrintWriter screen = new PrintWriter( new OutputStreamWriter( System.out ), true ); // … continued on next slide … So far this is identical to the previous version…

 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(10/11) TCP Echo Client (ii) //... continued from previous slide … EchoClient theClient = new EchoClient(remoteHost, remotePort); String lineFromUser = null, lineFromServer = null; for (;;) { lineFromUser = keyboard.readLine(); if ( lineFromUser.equals("quit") ) break; theClient.send(lineFromUser); lineFromServer = theClient.receive(); screen.println(lineFromServer); } However, This version isolates the core functionality of the client in a separate EchoClient class, and so the rest is much simpler than the previous version: The EchoClient class provides a constructor, plus simple send() and receive() methods…

 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(11/11) Exercise: Part II Use the remaining time to work through part II of today’s exercise. We will be demo-ing your Part II solutions at the end of today’s session!