Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.

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

Network Programming Chapter 11 Lecture 6. Networks.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Basic Socket Programming with Java. What is a socket?  Generally refers to a stream connecting processes running in different address spaces (across.
Socket Programming.
1 Java Networking – Part I CS , Spring 2008/9.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Networking Support In Java 2 Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java Socket Support Presentation by: Lijun Yuan Course Number: cs616.
COMP1681 / SE15 Introduction to Programming
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Application Layer PART VI.
Client/Server In Java An Introduction to TCP/IP and Sockets.
Networking Support In Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Networking Support In Java 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Networking java.net package, which provides support for networking. Its creators have called Java “programming for the Internet.” Socket :- A network socket.
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
Greg Jernegan Brandon Simmons. The Beginning…  The problem Huge demand for internet enabled applications and programs that communicate over a network.
Babak Esfandiari (based on slides by Qusay Mahmoud)
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
Introduction/Warmup Java Socket Programming.  Stream connecting processes running in different address spaces  Can be across a network or on the same.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
1 CSCD 330 Network Programming Winter 2015 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
Internet Applications and Network Programming Dr. Abraham Professor UTPA.
 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.
1 A TCP/IP Application Programming Perspective Chris Greenhalgh G53ACC.
Distributed Systems Concepts and Design Chapter 4.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
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.
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 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.
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.
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.
Socket Programming Introduction. Socket Definition A network socket is one endpoint in a two-way communication flow between two programs running over.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
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.
Java Network Programming Network Programming Spring 2000 Jeffrey E. Care
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
1 Netprog 2002 TCP/IP UDP/IP in Java Based on Java Network Programming and Distributed Computing.
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.
Distributed Systems CS Project 1: File Storage and Access Kit (FileStack) Recitation 1, Aug 29, 2013 Dania Abed Rabbou and Mohammad Hammoud.
Advanced Java Session 4 New York University School of Continuing and Professional Studies.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
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.
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.
Advance Computer Programming Networking Basics – explores the java.net package which provides support for networking. – Also Called “programming for the.
1 K. Salah Application Layer Module K. Salah Network layer duties.
Network Programming. These days almost all devices.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit9: Internet programming 1.
Object-Orientated Analysis, Design and Programming
Network Programming Introduction
MCA – 405 Elective –I (A) Java Programming & Technology
Beyond HTTP Up to this point we have been dealing with software tools that run on browsers and communicate to a server that generates files that can be.
An Introduction to TCP/IP and Sockets
Network Programming Introduction
CSCD 330 Network Programming
CSCD 330 Network Programming
Presentation transcript:

Socket Programming -What is it ? -Why bother ?

Basic Interface for programming networks at transport level It is communication end point Used for inter process communication over network Need IP address and port number Popularly used in client-server computing Connection oriented – TCP – Phone system – Delivery is guaranteed Connectionless – UDP – Postal system – Delivery is not guaranteed

Ports Represented by a positive (16 bit) integer Some ports are reserved for common services -FTP 21 -TELNET 23 -SMTP 25 -HTTP 80 User process generally use port value >= 1024

Socket communication A server (program) runs on a specific computer and has a socket bound to that port. The server waits and listens to socket for a client to make a connection request

Socket Communication Upon acceptance, the server gets a new socket bounds to a different port. It needs a new socket (different port number) so that it can continue to listen to the original socket for connection requests while serving the connected client.

Java socket library Through the classes in java.net, program can use TCP / UDP to communicate over the internet ‘URL’, ‘URLConection’, ‘Socket’, ‘ServerSockets’ - TCP ‘DatagramSocket’ / ‘DatagramPacket’ - UDP

TCP / IP in java Java.net.InetAddress: Represents an IP address (either IPv4 or IPv6 ) and has methods for performing DNS lookups Java.net.Socket: Represents a TCP socket Java.net.ServerSocket: Represents a server socket which is capable of writing for requests from clients

InetAddress Used to encapsulate both the numerical IP address and domain name for that address Factory methods to be used to create instance -static InetAddress getLocalHost() -static InetAddress getByName(String hostName) -static InetAddress getAllByName(String hostName)

Example InetAddress TODO

Client Socket Java wraps OS sockets (over TCP) by the objects of class java.net.Socket Socket( String remoteHost, int remotePort ) Create TCP socket and connects it to the remote host on the remote port (hand shake) Write and read using Streams: – InputStream getInputStream() – OutputStream getOutputStream()

Implementing a TCP/UDP client TODO

Server Socket This class implements server socket. A server socket waits for requests to come in over the network. It performs some operation based on that request, and possibly returns a result to the requester. A server socket is technically not a socket: when a client connects to a server socket, a TCP connection is made, and a (normal) socket is created for each end point.

Implementing a server

Server with Multithreading support TODO

Multithreaded model synchronous: you handle one request at a time, each in turn. pros: simple cons: any one request can hold up all the other requests fork: you start a new process to handle each request. pros: easy cons: does not scale well, hundreds of connections means hundreds of processes. fork() is the Unix programmer's hammer. Because it's available, every problem looks like a nail. It's usually overkill threads: start a new thread to handle each request. pros: easy, and kinder to the kernel than using fork, since threads usually have much less overhead cons: threaded programming can get very complicated very fast, with worries about controlling access to shared resources

Non-blocking Socket A non-blocking socket allows input/output operation on a channel without blocking the processes using it Single thread can handle multiple requests

Non-blocking System Model Server: the application receiving requests. Client: the set of applications sending requests to the server. Socket channel: the communication channel between client and server. It is identified by the server IP address and the port number. Data passes through the socket channel by buffer items. Selector: the main object of all non-blocking technology. It monitors the recorded socket channels and serializes the requests, which the server has to satisfy. Keys: the objects used by the selector to sort the requests. Each key represents a single client sub-request and contains information to identify the client and the type of the request.

Non-blocking socket architecture

Channels They can operate in non-blocking mode and are selectable Channel represents specific connection to a specific I/O service and encapsulates the state of that connection Buffers are the internal endpoints used by channel to send and receive data

Selectors This class manages information about a set of registered channels and their readiness status Each instance of Selector can monitor more socket channels, and thus more connections When something interesting happens on the channel, the selector informs the application to process the request

General algo of non-blocking server

Server Program TODO

Client Program TODO

‘Event-driven' model pros: – efficient and elegant – scales well - hundreds of connections means only hundreds of socket/state objects, not hundreds of threads or processes. cons: – more complex - you may need to build state machines. – requires a fundamentally different approach to programming that can be confusing at first

Java NIO Projects Netty - Mina - Grizzly -