CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.

Slides:



Advertisements
Similar presentations
Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
Advertisements

Using TCP sockets in Java Created by M Bateman, A Ruddle & C Allison As part of the TCP View project.
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.
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
Java Networking -- Socket Server socket class: ServerSocket wait for requests from clients. after a request is received, a client socket is generated.
System Programming Practical session 10 Java sockets.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
Client/Server In Java An Introduction to TCP/IP and Sockets.
© 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.
1 Fall 2005 Socket Programming Qutaibah Malluhi Computer Science and Engineering Qatar University.
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 java.net package, which provides support for networking. Its creators have called Java “programming for the Internet.” Socket :- A network socket.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
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.
SOCKET PROGRAMMING. Client/Server Communication At a basic level, network-based systems consist of a server, client, and a media for communication as.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 21.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
Internet Applications and Network Programming Dr. Abraham Professor UTPA.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
 TCP (Transport Control Protocol) is a connection-oriented protocol that provides a reliable flow of data between two computers.  TCP/IP Stack Application.
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.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
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.
© Lethbridge/Laganière 2005 Chap. 3: Basing Development on Reusable Technology The Client-Server Architecture A distributed system is a system in.
Remote Shell CS230 Project #4 Assigned : Due date :
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.
Socket Programming Using JAVA Asma Shakil Semester 1, 2008/2009.
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.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/11) Java Sockets and Simple Networking Joel Adams and Jeremy Frens.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
Java Sockets Tutorial Rahul Malik Nov 12, 2005.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Peter Lee April 8, 2004.
Part 4: Network Applications Client-server interaction, example applications.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
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.
Java Programming II Java Network (I) Java Programming II.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Java Packages Thread Example Java Socket Programming.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
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.
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
CS 5204 Fall 00 1 Distributed Programming low level: sending data among distributed computations higher level: supporting invocations among distributed.
Echo Networking COMP
Threads in Java Two ways to start a thread
Network Programming in Java CS 1111 Ryan Layer May 3, 2010
Lecture 21 Sockets 1 (Not in D&D) Date.
Networking COMP
Client-server Programming
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
Sockets and URLs 17-Sep-18.
CSI 4118 – UNIVERSITY OF OTTAWA
CS 390 Unix Programming Environment
Sockets and URLs 3-Dec-18.
Distributed Computing
CS18000: Problem Solving and Object-Oriented Programming
Presentation transcript:

CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming

CS390- Unix Programming Environment Client- Server Applications Client Application TCP/ IP interface Network TCP/ IP interface Server Application TCP/IP provides peer to peer communication between two applications Client Application initiates the conversation Server Application accepts the conversation Client Application generally requests the services and the Server Application provides services for these requests

CS390- Unix Programming Environment Application Responsibilities Client Application Locate and request service from a server Server Application Authentication: verifying the identity of the client Authorization: determining if the client is permitted to access these services Data security: Data exchanged is secure and is not revealed or compromised

CS390- Unix Programming Environment Sockets A socket is a 16-bit number that is used as an index to the socket descriptor table Each entry in this table references a socket data structure The socket data structure consists of all the information that is required to set up and exchange data over an IP connection A socket data structure is as follows:

CS390- Unix Programming Environment Socket Data Structure Socket Descriptor table SocketSocket details Family PF_INET Service SOCK_STREAM LocalIP RemoteIP LocalPort 2172 Socket Data Structure RemotePort 5143

CS390- Unix Programming Environment Port Numbers A port number is a 16-bit integer that represents the logical end point of a conversation The mechanism that enables a computer to support more than one IP conversation at a time Port numbers will mostly likely be different for the same conversation on the client and server computers

CS390- Unix Programming Environment An Example Program 1, , Port 52 Program 2, , Port Program 3, , Port 2832 Program 1, , Port 52 Program 2, , Port Program 3, , Port 2832

CS390- Unix Programming Environment Client/ Server Conversation Client Program Server Program Create a socket – socket() socket() – create a socket Connect to the server – connect()bind() – bind to a port number Send data to the server- write()listen() – get ready for requests Receive data from server – read()accept() – wait for clients Terminate the conversation- close()read() – Receive data from client write() – Send data to client close() – Terminate conversation

CS390- Unix Programming Environment Supporting concurrent clients Multiple Socket Server s1 = socket() //create a socket Bind(s1,port_number)//Bind the socket to port Listen(s1)//place socket to listen s2= accept(s1)//wait for client conversation Create_process(client_handler, s2) // create a new process to service the client requests

CS390- Unix Programming Environment Client Socket client_handler (client_socket) read(client_socket) write(client_socket) close(client_socket) The server creates a new process or thread to handle every new client request The client connection is serviced by the new socket that was returned by the accept() call The original socket is freed up to handle another client request

CS390- Unix Programming Environment Example: A Distributed File viewer service (DFVS) Client Program Get me c:\test.txt Server Program Image of c:\test.txt Hard Disk The distributed file service consists of the following components Client Program Connect to the remote server program Request a file by name Receive an image of the actual file Display the file to the user

CS390- Unix Programming Environment Example: (DFVS) Server Program Wait for the client request Read the file from the local hard disk Send an image of the file to the remote client The view of the application is as follows:

CS390- Unix Programming Environment Example contd… Client Program Server Program Port 1031 TCP/IP Hard Disk Client Serversocket() connect( ,1031)bind(1031) write(c:\test.txt)listen() read(data-area)accept() close()read(fileName) display(data-area)readFromDisk(fileName,dataArea) write(dataArea) close()

CS390- Unix Programming Environment Example: contd… Read the file from the server given: Server IP : Server Port: 1031 Client IP: File Name: c:\test.txt

CS390- Unix Programming Environment Sockets in Java The java.net library provides several classes that enable socket-based communication in java The Java socket classes are: java.net.Socket java.net.ServerSocket java.net.DatagramSocket java.net.SocketImpl Check out documentation for more details

CS390- Unix Programming Environment Parameters in Java Class constructors String Host Host name: e.g. “queen.mcs.drexel.edu” IP Address: Use nslookup to identify IP addresses Int port Integer port number InetAddress address: class that represents Internet Protocol address. Has several methods. Check reference book.

CS390- Unix Programming Environment Implementing a Server Create a socket, use the ServerSocket class ServerSocket s = new ServerSocket(4444); Socket listens to port 4444 Accept connection from client Socket Client_Socket = s.accept(); Creates a socket that communicates with the client Open the input and output stream to/from client DataInputStream in = new DataInputStream(Client_Socket.getInputStream()); PrintStream ps = new PrintStream(client_Socket.getOutputStream());

CS390- Unix Programming Environment Implementing a Server Close all the sockets and Streams s.close(); Client_Socket.close(); in.close(); ps.close(); Upon closing the sockets and streams terminates the session between the server process and client process

CS390- Unix Programming Environment Implementing a Client Create a socket Specify the hostname or IP and the port where the socket will be created Socket c = new Socket(“queen.mcs.drexel.edu”,4444); If you are using a single machine then use localhost as your hostname Open the input and output stream DataInputStream in = new DataInputStream(c.getInputStream()); PrintStream out = new PrintStream(c.getOutputStream());

CS390- Unix Programming Environment Implementing the client Close the socket and streams c.close(); in.close(); out.close();

CS390- Unix Programming Environment Sample Server class EchoServer { public static void main(String args[]) { try { ServerSocket s = new ServerSocket(4444); Socket client_socket = s.accept(); DataInputStream in = new DataInputStream(client_socket.getInputStream()); PrintStream out = new PrintStream(client_socket.getOutputStream()); …

CS390- Unix Programming Environment Sample Server contd… … out.println(“Hello!enter Bye to exit. \r”); boolean done = false; while (!done) { String str = in.readLine(); if(str == null){ done = true; } else { out.println(“Echo :”+str+” \r”); if(str.trim().equals(“BYE”)) done = true; } }…

CS390- Unix Programming Environment Sample Server contd… client_socket.close(); } catch (Exception e) { System.out.println(e.toString()); } } } //end of class EchoServer What is the name of this file?

CS390- Unix Programming Environment Sample Client class EchoClient { public static void main(String args[]) { try { Socket c = new Socket(“queen.mcs.drexel.edu”, 4444); // Note that when you are working on queen try to keep the port number > 4200 DataInputStream in = new DataInputStream(c.getInputStream()); boolean more = true; while(more) { String str = in.readLine(); if(str == null) more = false; else System.out.println(str); }…

CS390- Unix Programming Environment Sample Client contd… } catch(IOException ioe) { System.out.println(“Error “+ioe); } } //end of class EchoClient Now that you have a sample application, try to work on this and get more information from the reference book for implementing your term project That finishes the tutorial on Java and Socket Programming in Java Next lecture, we will go through some of the components of the operating system like file manager, memory manager etc.