The Socket API 9/17/2018.

Slides:



Advertisements
Similar presentations
Java Network Programming Vishnuvardhan.M. Dept. of Computer Science - SSBN Java Overview Object-oriented Developed with the network in mind Built-in exception.
Advertisements

Transport Layer3-1 Transport Overview and UDP. Transport Layer3-2 Goals r Understand transport services m Multiplexing and Demultiplexing m Reliable data.
Introduction 1-1 Chapter 3 Transport Layer Intro and Multiplexing Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley.
Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
CCNA – Network Fundamentals
Network Programming Chapter 11 Lecture 6. Networks.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 OSI Transport Layer Network Fundamentals – Chapter 4.
Computer Communication Digital Communication in the Modern World Transport Layer Multiplexing, UDP
Chapter 3: Transport Layer
Socket Programming.
1 Java Networking – Part I CS , Spring 2008/9.
Transport Layer3-1 Transport Layer Our goals: r understand principles behind transport layer services: m multiplexing/demultipl exing m reliable data transfer.
Java Socket Support Presentation by: Lijun Yuan Course Number: cs616.
Lecture 8 Chapter 3 Transport Layer
1 School of Computing Science Simon Fraser University CMPT 771/471: Internet Architecture and Protocols Socket Programming Instructor: Dr. Mohamed Hefeeda.
3-1 Transport services and protocols r provide logical communication between app processes running on different hosts r transport protocols run in end.
8-1 Transport Layer Our goals: r understand principles behind transport layer services: m multiplexing/demultipl exing m reliable data transfer m flow.
CS 352-Socket Programming & Threads Dept. of Computer Science Rutgers University (Thanks,this slides taken from er06/
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 3 Inter-process Communication.
IP and Errors IP Best Effort Datagrams can be: –Lost –Delayed –Duplicated –Delivered out of order –Corrupted.
Data Communications and Computer Networks Chapter 3 CS 3830 Lecture 12 Omar Meqdadi Department of Computer Science and Software Engineering University.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
The Socket API Unit – Background 4.2 The Socket Metaphor In IPC
Transport Layer 3-1 Chapter 3 Transport Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012 Part.
Transport Layer1 Ram Dantu (compiled from various text books)
Lecture91 Administrative Things r Return homework # 1 r Review some problems in homework # 1 r Questions about grading? Yona r WebCT for CSE245 is working!
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.
Chapter 2 Applications and Layered Architectures Sockets.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Transport Layer 3-1 Chapter 3 Outline r 3.1 Transport-layer services r 3.2 Multiplexing and demultiplexing r 3.3 Connectionless transport: UDP.
Socket Programming Introduction. Socket Definition A network socket is one endpoint in a two-way communication flow between two programs running over.
Transport Layer3-1 Chapter 3 Transport Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley,
Part 4: Network Applications Client-server interaction, example applications.
MULTIPLEXING/DEMULTIPLEXING, CONNECTIONLESS TRANSPORT.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Transport Layer3-1 Chapter 3: Transport Layer Our goals: r understand principles behind transport layer services: m multiplexing/demultipl exing m reliable.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
1 Network Communications A Brief Introduction. 2 Network Communications.
Introduction 1-1 source application transport network link physical HtHt HnHn M segment HtHt datagram destination application transport network link physical.
Network Programming. These days almost all devices.
CSEN 404 Transport Layer I Amr El Mougy Lamia Al Badrawy.
Distributed Systems1 Socket API  The socket API is an Interprocess Communication (IPC) programming interface originally provided as part of the Berkeley.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Chapter 7: Transport Layer
Object-Orientated Analysis, Design and Programming
Chapter 3 Transport Layer
Introduction to Networks
Chapter 3 Transport Layer
The Transport Layer Implementation Services Functions Protocols
Transport Layer Slides are originally from instructor: Carey Williamson at University of Calgary Very minor modification are made Notes derived from “Computer.
Chapter 9: Transport Layer
Client-Server Communication
Chapter 3 outline 3.1 Transport-layer services
MCA – 405 Elective –I (A) Java Programming & Technology
06- Transport Layer Transport Layer.
CS 1652 Jack Lange University of Pittsburgh
Introduction to Networks
Transport Layer Our goals:
September 19th, 2013 CS1652 Jack Lange University of Pittsburgh
Process-to-Process Delivery:
CSCD 330 Network Programming
Process-to-Process Delivery: UDP, TCP
Computer Networks Protocols
Chapter 3 Transport Layer
Transport Layer 9/22/2019.
Transport Layer Our goals:
Presentation transcript:

The Socket API 9/17/2018

Introduction The socket API is an Interprocessing Communication (IPC) programming interface originally provided as part of the Berkeley UNIX operating system. It has been ported to all modern operating systems, including Sun Solaris and Windows systems. It is a de facto standard for programming IPC, and is the basis of more sophisticated IPC interface such as remote procedure call (RPC) and remote method invocation (RMI). 9/17/2018

The conceptual model of the socket API Logical port numbers: 1,024 -- 65,535 (216 - 1) 9/17/2018

The socket API A socket API provides a programming construct termed a socket. A process wishing to communicate with another process must create an instance, or instantiate, such a construct (socket) The two processes then issue operations provided by the API to send and receive data (e.g., a message) 9/17/2018

Datagram Socket vs. Stream Socket A socket programming construct can make use of either the UDP (User Datagram Protocol ) or TCP (Transmission Control Protocol ). A socket is a generalization of the UNIX file access mechanism that provides an endpoint for communication. A datagram consists of a datagram header, containing the source and destination IP addresses, and a datagram data area. Sockets that use UDP for transport are known as datagram sockets, while sockets that use TCP are termed stream sockets. Q: can a process contain both UDP and TCP sockets? 9/17/2018

UDP vs. TCP reliable, in-order delivery (TCP) congestion control flow control connection setup unreliable, unordered delivery: UDP “best-effort” service loss tolerant; rate sensitive DNS, streaming multimedia apps 9/17/2018

Connection-oriented & connectionless Datagram socket Datagram sockets can support both connectionless and connection-oriented communications at the application layer. This is so because even though datagrams are sent or received without the notion of connections at the transport layer, the runtime library of the socket API can create and maintain logical connections for datagrams exchanged between two processes The runtime library of an API is a set of software that is bound to the program during execution in support of the API. 9/17/2018

Connection-oriented & connectionless Datagram socket 9/17/2018

The Java Datagram Socket API There are two Java classes for the datagram socket API: - the DatagramSocket class for the sockets. - the DatagramPacket class for the datagrams. A process wishing to send or receive data using this API must instantiate a DatagramSocket object--a socket DatagramPacket object--a datagram Each socket in a receiver process is said to be bound to a UDP port of the machine local to the process. 9/17/2018

The Java Datagram Socket API To send a datagram to another process, a process: creates a DatagramSocket (socket) object, and an object that represents the datagram itself. This datagram object can be created by instantiating a DatagramPacket object, which carries a reference to a byte array and the destination address--host ID and port number, to which the receiver’s socket is bound. issues a call to the send method in the DatagramSocket object, specifying a reference to the DatagramPacket object as an argument. 9/17/2018

The Java Datagram Socket API DatagramSocket mySocket = new DatagramSocket(); // any available port number byte[ ] byteMsg = message.getBytes( ); DatagramPacket datagram = new DatagramPacket (byteMsg , byteMsg.length, receiverHost, receiverPort); mySocket.send(datagram); mySocket.close( ); 9/17/2018

The Java Datagram Socket API In the receiving process, a DatagramSocket (socket) object must also be instantiated and bound to a local port, the port number must agree with that specified in the datagram packet of the sender. To receive datagrams sent to the socket, the process creates a datagramPacket object which references a byte array, and calls a receive method in its DatagramSocket object, specifying as argument a reference to the DatagramPacket object. 9/17/2018

The Java Datagram Socket API DatagramSocket mySocket = new DatagramSocket(port); byte[ ] recMsg = new byte[MAX_LEN]; DatagramPacket datagram = new DatagramPacket(recMsg, MAX_LEN); mySocket.receive(datagram); // blocking and waiting mySocket.close( ); 9/17/2018

The Data Structures in the sender and receiver programs 9/17/2018

The program flow in the sender and receiver programs Q: Why the sender socket needs a local port number? 9/17/2018

Event synchronization with the connectionless datagram sockets API 9/17/2018

Setting timeout To avoid indefinite blocking, a timeout can be set with a socket object: void setSoTimeout(int timeout)    Set a timeout for the blocking receive from this socket, in milliseconds. int timeoutPeriod = 30000; // 30 seconds mySocket.setSoTimeout(timeoutPeriod); Once set, the timeout will be in effect for all blocking operations. 9/17/2018

Key Methods and Constructors 9/17/2018

The coding 9/17/2018

Connectionless sockets With connectionless sockets, it is possible for multiple processes to simultaneously send datagrams to the same socket established by a receiving process, in which case the order of the arrival of these messages will be unpredictable, in accordance with the UDP protocol 9/17/2018

Code samples Example1Sender.java, ExampleReceiver.java MyDatagramSocket.java, Example2SenderReceiver.java , Example2ReceiverSender.java /home/faculty/yhwang1/public_html/SWE622/Sample_Codes/chapter4 (m2) 9/17/2018

Connection-oriented Datagram Socket API It is uncommon to employ datagram sockets for connection-oriented communication; the connection provided by this API is rudimentary and typically insufficient for applications that require a true connection. Stream-mode sockets are more typical and appropriate for connection-oriented communication.   9/17/2018

Methods calls for connection-oriented datagram socket Once a datagram socket A is connected with a remote / local socket B, it can only exchange data with socket B. If a datagram msg is sent from the connected socket A to another socket C, an exception—IllegalArgumentException, will occur. If a datagram msg is sent from socket D to socket A, the msg will be ignored. 9/17/2018

Connection-oriented Datagram Socket The connection is unilateral, that is, it is enforced only on one side, where a connect() call is issued. The socket on the other side is free to send and receive data to and from other sockets. MyDatagramSocket mySocket = new MyDatagramSocket(myPort); mySocket.receiveMessage(); mySocket.connect (senderHost, senderPort); // ex-3 9/17/2018

The Stream-Mode Socket API The datagram socket API supports the exchange of discrete units of data. the stream socket API provides a model of data transfer based on the stream-mode I/O of the Unix operating systems. By definition, a stream-mode socket supports connection-oriented communication only. 9/17/2018

Stream-Mode Socket API (connection-oriented socket API) 9/17/2018

Stream-Mode Socket API A stream-mode socket is established for data exchange between two specific processes. Data stream is written to the socket at one end, and read from the other end. A data stream cannot be used to communicate with more than one process. 9/17/2018

Stream-Mode Socket API In Java, the stream-mode socket API is provided with two classes: ServerSocket: for accepting connections; we will call an object of this class a connection socket. Socket: for data exchange; we will call an object of this class a data socket. 9/17/2018

Stream-Mode Socket API ServerSocket connectionSocket = new ServerSocket(portNo); Socket dataSocket = connectionSocket.accept(); // waiting for a connection request OutputStream outStream = dataSocket.getOutputStream(); PrintWriter socketOutput = new PrintWriter(new OutputStreamWriter(outStream)); socketOutput.println(message); // send a msg into stream socketOutput.flush(); dataSocket.close( ); connectionSocket.close( ); SocketAddress sockAddr = new InetSocketAddress( acceptHost, acceptorPort); Socket mySocket = new Socket(); mySocket.connect (sockAddr, 60000); // 60 sec timeout Socket mySocket = new Socket(acceptorHost, acceptorPort); InputStream inStream = mySocket.getInputStream(); BufferedReader socketInput = new BufferedReader(new InputStreamReader( inStream)); String message = socketInput.readLine( ); mySocket.close( ); 9/17/2018

Stream-Mode Socket API program flow (client) 9/17/2018

The server (the connection listener) 9/17/2018

Key methods in the ServerSocket class accept() Note: accept() is a blocking operation. 9/17/2018

Key methods in the Socket class A read operation on an InputStream is blocking. A write operation on an OutputStream is nonblocking. 9/17/2018

Connection-oriented socket API-3 9/17/2018

Connection-oriented socket API-3 9/17/2018

Connectionless socket API 9/17/2018

Example 4 Event Diagram 9/17/2018

Example4 9/17/2018

Secure Sockets Secure sockets perform encryption on the data transmitted. The JavaTM Secure Socket Extension (JSSE) is a Java package that enables secure Internet communications. It implements a Java version of SSL (Secure Sockets Layer) and TLS (Transport Layer Security) protocols It includes functionalities for data encryption, server authentication, message integrity, and optional client authentication. Using JSSE, developers can provide for the secure passage of data between a client and a server running any application protocol. 9/17/2018

The Java Secure Socket Extension API Import javax.net.ssl; // provides classes related to creating and configuring secure socket factories. Class SSLServerSocket is a subclass of ServerSocket, and inherits all its methods. Class SSLSocket is a subclass of Socket, and inherits all its methods. There are also classes for Certification Handshaking KeyManager SSLsession 9/17/2018