Application Development with TCP/IP. Brian S. Mitchell Drexel University



Similar documents
Socket Programming in Java

Java Network. Slides prepared by : Farzana Rahman

Network/Socket Programming in Java. Rajkumar Buyya

Lesson: All About Sockets

Division of Informatics, University of Edinburgh

Network Communication

Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets

Creating a Simple, Multithreaded Chat System with Java

NETWORK PROGRAMMING IN JAVA USING SOCKETS

Limi Kalita / (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 5 (3), 2014, Socket Programming

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

Socket-based Network Communication in J2SE and J2ME

Network Programming using sockets

Socket Programming. Announcement. Lectures moved to

The difference between TCP/IP, UDP/IP and Multicast sockets. How servers and clients communicate over sockets

Assignment 4 Solutions

JAVA Program For Processing SMS Messages

Abhijit A. Sawant, Dr. B. B. Meshram Department of Computer Technology, Veermata Jijabai Technological Institute

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

Java Programming: Sockets in Java

Network Programming TDC 561

Data Communication & Networks G

Computer Networks/DV2 Lab

!"# $ %!&' # &! ())*!$

Socket Programming. Srinidhi Varadarajan

Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol).

Communicating with a Barco projector over network. Technical note

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

Socket programming. Socket Programming. Languages and Platforms. Sockets. Rohan Murty Hitesh Ballani. Last Modified: 2/8/2004 8:30:45 AM

TITLE NETWORK PROGRAMMING (SECURED CLIENT-SERVER CHAT APPLICATION) A PROJECT REPORT PRESENTED ACHILE UGBEDE JOHN CE/2007/165

Domain Name System (DNS) Omer F. Rana. Networks and Data Communications 1

Building a Multi-Threaded Web Server

An Overview of Java. overview-1

Socket Programming. Request. Reply. Figure 1. Client-Server paradigm

Agenda. Network Programming and Java Sockets. Introduction. Internet Applications Serving Local and Remote Users

ICT SEcurity BASICS. Course: Software Defined Radio. Angelo Liguori. SP4TE lab.

Tutorial on Socket Programming

ELEN 602: Computer Communications and Networking. Socket Programming Basics

Network-Oriented Software Development. Course: CSc4360/CSc6360 Instructor: Dr. Beyah Sessions: M-W, 3:00 4:40pm Lecture 2

Network Programming with Sockets. Process Management in UNIX

Socket = an interface connection between two (dissimilar) pipes. OS provides this API to connect applications to networks. home.comcast.

IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking.

Objectives of Lecture. Network Architecture. Protocols. Contents

SSC - Communication and Networking Java Socket Programming (II)

DNS: Domain Names. DNS: Domain Name System. DNS: Root name servers. DNS name servers

Network-based Applications. Pavani Diwanji David Brown JavaSoft

String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket.

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software

Intel Retail Client Manager Audience Analytics

Operating Systems Design 16. Networking: Sockets

MATLAB/Simulink TCP/IP Communication

Ethernet. Ethernet. Network Devices

Network Models OSI vs. TCP/IP

File Sharing. Peter Lo. CP582 Peter Lo

What is an I/O Stream?

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

UNIX Sockets. COS 461 Precept 1

Transparent Redirection of Network Sockets 1

TP1 : Correction. Rappels : Stream, Thread et Socket TCP

An Android-based Instant Message Application

Introduction to Socket programming using C

Implementing and testing tftp

Socket programming. Complement for the programming assignment INFO-0010

Application Architecture

TFTP Usage and Design. Diskless Workstation Booting 1. TFTP Usage and Design (cont.) CSCE 515: Computer Network Programming TFTP + Errors

Generalised Socket Addresses for Unix Squeak

Mail User Agent Project

Configuring CSS Remote Access Methods

WRITING DATA TO A BINARY FILE

JAVA - FILES AND I/O

Chapter 11. User Datagram Protocol (UDP)

TCP/IP - Socket Programming

Socket Programming in C/C++

AVRO - SERIALIZATION

1 Introduction: Network Applications

Immotec Systems, Inc. SQL Server 2005 Installation Document

CPS221 Lecture: Layered Network Architecture

Chapter 3. Internet Applications and Network Programming

The POSIX Socket API

Java Programming Unit 10. Stock Price Quotes with URL, Sockets, and RMI

Introduction To Computer Networking

! "# $%&'( ) * ).) "%&' 1* ( %&' ! "%&'2 (! ""$ 1! ""3($

Preface. Intended Audience

public static void main(string[] args) { System.out.println("hello, world"); } }

Lab 4: Socket Programming: netcat part

transmission media and network topologies client/server architecture layers, protocols, and sockets

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

Networks. Inter-process Communication. Pipes. Inter-process Communication

Introduction to Socket Programming Part I : TCP Clients, Servers; Host information

Advanced Network Programming Lab using Java. Angelos Stavrou

Application Layer. CMPT Application Layer 1. Required Reading: Chapter 2 of the text book. Outline of Chapter 2

Client-server Sockets

Chapter 2: Remote Procedure Call (RPC)

AN APPLICATION OF INFORMATION RETRIEVAL IN P2P NETWORKS USING SOCKETS AND METADATA

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

Intranet, Extranet, Firewall

ExempleRMI.java. // Fichier de defintion des droits et proprietes // System.setProperty("java.security.policy","../server.java.

Transcription:

Application Development with TCP/IP Brian S. Mitchell Drexel University

Agenda TCP/IP Application Development Environment Client/Server Computing with TCP/IP Sockets Port Numbers The TCP/IP Application Programming Interface (API) Example: A Distributed File Viewer Java Socket Implementation

TCP/IP Application Development Environment Network Media (Wire) Network Interface Card Control Header Data Area IEEE 802.2 LLC Frame TCP /IP Protocol Suite Datagram Header Data Area IP Datagram Datagram Header Data Area TCP Datagram TCP/IP applications are constructed using the sockets interface Open standard TCP/IP Application Development Interface (Sockets) TCP/IP Applications Extensions to support the Windows (3.1, 95, NT) environment have been developed by an open committee (Winsock)

Client/Server Model with TCP/IP Client Application TCP/IP Interface Network TCP/IP Interface Server Application TCP/IP provides peer to peer communication between two application processes The peer applications can execute on the same or different machines Client application initiates the conversation Server application accepts the conversation Client applications generally request services whereas server applications generally provide services Example: CETS

Application Responsibilities Client Applications Locate and request a service from a server Can run on a single (DOS, Windows 3.x) or a multi-process (Windows 95, NT, OS2, UNIX, MVS) operating system Server Applications Server has additional responsibilities beyond providing a service to a client Authentication - verifying the identity of the client Authorization - determining if a given client is permitted to access the service that the server supplies Data Security - guaranteeing that the data that is exchanged between the client and the server is not revealed or compromised

Application Responsibilities (con t) Privacy - keeping information about an individual (e.g. user ID and password) from unauthorized access Protection - guaranteeing that network applications cannot abuse system resources Requires a multiprocessing operating system to concurrently support more than one client.

Application Development with TCP/IP Checklist IP Address Socket Port Number Socket Verbs (Functions)

Sockets Socket Descriptor Table Socket Data Structure Socket 37 80 9654 3156 9512 Socket Details Family: PF_INET Service: SOCK_STREAM (TCP) Local IP: 172.21.100.8 Remote IP: 172.21.100.45 Local Port: 3571 Remote Port: 6358 A socket is a 16-bit number that is used as an index into a socket descriptor table Each entry in this table references a socket data structure. The socket data structure contains all of the information that is required to setup and exchange data over an IP conversation The socket model has many advantages Support for different communication protocols (Raw IP, UDP/IP, TCP/IP) Makes receiving and sending data over a network synonymous with performing read and write operations on a local file.

Sockets (con t) Socket Descriptor Table Socket Data Structure Socket 37 80 9654 3156 9512 Socket Details Family:?????????? Service:?????????? Local IP:?????????? Remote IP:?????????? Local Port:?????????? Remote Port:?????????? When a socket is first created it does not contain enough information to initiate a network conversation. Special socket functions (TCP/IP API s) must be called in order to populate the socket data structure

Port Numbers Program 1, 172.21.100.7, Port 52 Program 2, 172.21.100.7 Port 87... Program n, 172.21.56.2 Port 382 172.21.100.45 LAN Program 1, 172.21.100.45 Port 97 Program 2, 172.21.100.45 Port 156 172.21.100.7 Program 1, 172.21.100.45, Port 1041 172.21.56.2 A port number is a 16-bit integer that represents the logical endpoint of a conversation The mechanism that enables a computer to support more than one IP conversation at a time Port numbers can (and most likely will) be different for the same conversation on the client and server computers

Port Numbers (con t) What port is handling the phone directory? Client Application The phone directory service is listening on port number 158 Port Mapper Service Phone Directory Service Port 158 Port Database Connect 172.21.100.87:158 A Client application can obtain the server application port number in one of two ways Must know the port number in advance Provided by the server s documentation Can determine the port number dynamically by sending a message to the port mapper service All services that want their port number to be found by name must register (and deregister) with the port mapper service Port number is obtained by calling the getportbyname (...) API

TCP/IP Client/Server Conversation Client Program Create a socket - socket( ) Connect to the server - connect( ) Send data to the server - write( ) Receive data from the server - read( ) Terminate the conversation - close( ) Server Program socket( ) - create a socket bind( ) - bind program to a port number listen( ) - get ready to accept client requests accept( ) - wait for a client request read( ) - Receive data from the client write( ) - Send data to the client close( ) - Terminate the conversation TCP/IP socket programs are controlled by a series of API s: Socket, connect, accept, read, write, close, listen, bind, accept

Supporting concurrent clients with Socket Servers Multiprocessing Socket Server s1 = socket () bind (s1, port_number) listen (s1) s2 = accept (s1) create_process(client_handler, s2) // Create a socket // Bind the socket to a port // Place the socket into a listening mode // Wait for a client connection accept( ) returns a new socket to handle the client connection // Create a new process to service the // client request client_handler (client_socket) read(client_socket) write(client_socket) close(client_socket) The server creates a new process or thread to handle the clients request 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

Example: A Distributed File Viewer Service Get me file c:\test.txt Client Program Image of the c:\test.txt file Server Program Hard Disk The distributed file service will consist of the following components Client Program Connect to the remote server program Request a file by name Receive an image of the actual file from the server program Display the file image for the user to view Server Program Wait for a client request Read a file from the local hard disk based on the client request Send an image of the file to the remote client

Example: A Distributed File Server (con t) Client Program TCP/IP Conversation Server Program Port 1031 Hard Disk 171.21.100.7 Client socket ( ) connect (172.21.100.45,1031) write ( c:\test.txt ) read (data-area) close ( ) display_data(data_area) 171.21.100.45 Server socket () bind (1031) listen ( ) accept ( ) read (file_name) read_file_from_disk (file_name, data_area) write (data_area) close () Read the file c:\test.txt on the server given Client IP = 172.21.100.7 Server IP = 172.21.100.45 File read service port number = 1031

Sockets in Java The java.net package 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 See the Java documentation for details on these classes

Parameters in Java Class Constructors String host: String host can be specified either as machine name or IP address. For queen.mcs.drexel.edu, machine name is queen.mcs.drexel.edu", IP address is "129.25.6.176". In unix, if you know the machine name, then you can use "nslookup" to identify the IP address of the machine if the machine is connected to the network. int port: integer port number boolean stream: It specify whether communication through the socket based on TCP protocol, or UDP datagram protocol. The defaulat protocol is TCP.

Parameters in Java Class Constructors (con t) InetAddress address: InetAddress is the class that represents an Internet Protocol(IP) address. It does not have a constructor, but instead it has several methods which return the InetAddress objects. Method getlocalhost() returns an InetAddress for the local host. GetAllByName() returns an array of InetAddress that represents all of the available addresses for a host specified by name; getbyname() returns the InetAddress of a host specified by name. The InetAddress class definition is shown on the next slide

The InetAddress Class public final class InetAddress extends Object { // Methods public boolean equals(object obj); public byte[] getaddress(); public static InetAddress[] getallbyname(string host); public static InetAddress getbyname(string host); public String gethostname(); public static InetAddress getlocalhost(); public int hashcode(); public String tostring(); }

Implementing A Server Create a socket, use the ServerSocket class ServerSocket s = new ServerSocket(4444) Socket listens to port 4444 Accept a connection request by a client Socket client_socket=s.accept(); Creates a socket that communicates with the client Open the input and output stream to/from the client DataInputStream in = new DataInputStream(client_socket.getInputStream()); PrintStream out = new PrintStream(client_socket.getOutputStream());

Implementing a Server Close the sockets s.close(); client_socket.close(); in.close(); out.close(); Closing the sockets and streams terminates the session between the server process and the client process

Implementing a Client Create a socket Specify server host name or IP address and port number Socket c= new Socket( queen.mcs.drexel.edu", 4444) If you only have a single machine you can use the 127.0.0.1 local loopback address Open the input and output stream on the socket DataInputStream in = new DataInputStream(c.getInputStream()); // get input stream PrintStream out = new PrintStream(c.getOutputStream()); // get output stream

Implementing the Client Close the sockets in.close(); // close the input stream out.close(); // close the output stream c.close(); // close the client socket

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());...

Sample Server 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; } }...

Sample Server client_socket.close(); } catch (Exception e) { System.out.println(e); } } } //end of class EchoServer

Sample Client class EchoClient { public static void main(string[] args) { try { Socket c = new Socket( queen.mcs.drexel.edu", 4444); DataInputStream in = new DataInputStream(c.getInputStream()); bolean more = true; while (more) { String str = in.readline(); if (str == null) more = false; else System.out.println(str); }...

Sample Client } catch (IOException e) { System.out.println("Error" + e); } } //end of class EchoClient