Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub

Size: px
Start display at page:

Download "Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub"

Transcription

1 Lebanese University Faculty of Science I Master 1 degree Computer Science Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub

2 Starting Network Programming in Java Chapter IV 2

3 Objectives 1. know how to determine the host machine's IP address via a Java program; 2. know how to use TCP sockets in both client programs and server programs; Core package java.net contains a number of very useful classes that allow programmers to carry out network programming very easily. 3

4 The InetAddress Class One of the classes within package java.net is called InetAddress, which handles Internet addresses both as host names and as IP addresses. Static method getbyname of this class uses DNS (Domain Name System) to return the Internet address of a specified host name as an InetAddress object. In order to display the IP address from this object, we can simply use method println (which will cause the object's tostring method to be executed). Since method getbyname throws the checked exception UnknownHostException if the host name is not recognized, we must either throw this exception or (preferably) handle it with a catch clause. 4

5 Example IPFinder.java 5

6 The InetAddress Class InetAddress has three static methods that return suitably initialized InetAddress objects given a little information. They are: public static InetAddress getbyname(string hostname) throws UnknownHostException public static InetAddress[] getallbyname(string hostname) throws UnknownHostException public static InetAddress getlocalhost( ) throws UnknownHostException These three methods have to go outside Java and the local system to get their work done. The other methods in this class, such as getaddress( ) and gethostname( ), mostly work with the information provided by one of these three methods. They do not make network connections; on the rare occasions that they do, they do not throw any exceptions. 6

7 public static InetAddress[ ] getallbyname(string hostname) throws UnknownHostException Some computers have more than one Internet address. Given a hostname, InetAddress.getAllByName() returns an array that contains all the addresses corresponding to that name. Its use is straightforward: InetAddress[] addresses = InetAddress.getAllByName(" Like InetAddress.getByName( ), InetAddress.getAllByName( ) can throw an UnknownHostException, so you need to enclose it in a try block or declare that your method throws UnknownHostException. 7

8 Example AllAddressesOfGoogle.java 8

9 public static InetAddress getlocalhost( ) throws UnknownHostException The InetAddress class contains one final means of getting an InetAddress object. The static method InetAddress.getLocalHost() returns the InetAddress of the machine on which it's running. Like InetAddress.getByName( ) and InetAddress.getAllByName( ), it throws an UnknownHostException when it can't find the address of the local machine (though this really shouldn't happen). Its use is straightforward: InetAddress me = InetAddress.getLocalHost( ); 9

10 Example MyLocalIPAddress.java 10

11 Getter Methods The InetAddress class contains three getter methods that return the hostname as a string and the IP address as both a string and a byte array: public String gethostname( ) public String gethostaddress( ) public byte[] getaddress( ) There are NO corresponding sethostname( ) and setaddress( ) methods. 11

12 public String gethostname( ) The gethostname( ) method returns a String that contains the name of the host with the IP address represented by this InetAddress object. For example: InetAddress machine = InetAddress.getLocalHost( ); String localhost = machine.gethostname( ); The gethostname( ) method is particularly useful when you're starting with a dotted quad IP address rather than the hostname. 12

13 Example ReverseTest.java 13

14 public String gethostaddress( ) The gethostaddress() method returns a string containing the dotted quad format of the IP address. 14

15 public byte[] getaddress( ) If you want to know the IP address of a machine (and you rarely do), getaddress( ) returns an IP address as an array of bytes in network byte order. The most significant byte (i.e., the first byte in the address's dotted quad form) is the first byte in the array, or element zero remember, Java array indices start with zero. The bytes returned are unsigned, which poses a problem. Unlike C, Java doesn't have an unsigned byte primitive data type. Bytes with values higher than 127 are treated as negative numbers. Therefore, if you want to do anything with the bytes returned by getaddress( ), you need to promote the bytes to ints and make appropriate adjustments. Here's one way to do it: int unsignedbyte = signedbyte < 0? signedbyte : signedbyte; One reason to look at the raw bytes of an IP address is to determine the type of the address. Test the number of bytes in the array returned by getaddress( ) to determine whether you're dealing with an IPv4 or IPv6 address. 15

16 Example AddressTests.java 16

17 TCP Sockets Chapter V 17

18 Using Sockets Different processes (programs) can communicate with each other across networks by means of sockets. Java implements both TCP/IP sockets and datagram sockets (UDP sockets). Very often, the two communicating processes will have a client/server relationship. Sockets allow the programmer to treat a network connection as just another stream onto which bytes can be written and from which bytes can be read. Sockets shield the programmer from low-level details of the network, such as error detection, packet sizes, packet retransmission, network addresses, and more. 18

19 Socket Basics A socket can perform seven basic operations: 1. Connect to a remote machine 2. Send data 3. Receive data 4. Close a connection 5. Bind to a port 6. Listen for incoming data 7. Accept connections from remote machines on the bound port Java's Socket class, which is used by both clients and servers, has methods that correspond to the first four of these operations. The last three operations are needed only by servers, which wait for clients to connect to them. 19

20 TCP Sockets A communication link created via TCP/IP sockets is a connection-oriented link. This means that the connection between server and client remains open throughout the duration of the dialogue between the two and is only broken (under normal circumstances) when one end of the dialogue formally terminates the exchanges (via an agreed protocol). Since there are two separate types of process involved (client and server), we shall examine them separately, taking the server first. 20

21 TCP Sockets Keyboard Monitor Input stream InFromUser Client process Server Welcome socket Server process Output stream OutToServer InFromServer Client TCP socket Input stream Output stream OutToClient InFromClient Server Connection socket Input stream To network From network To network From network 21

22 TCP Sockets Server Side Setting up a server process requires five steps Create a ServerSocket object. The ServerSocket constructor requires a port number ( , for nonreserved ones) as an argument. For example: ServerSocket servsock = new ServerSocket(1234); In this example, the server will await ('listen for') a connection from a client on port Put the server into a waiting state. The server waits indefinitely ('blocks') for a client to connect. It does this by calling method accept of class ServerSocket, which returns a Socket object when a connection is made. For example: Socket link = servsock.accept(); 22

23 TCP Sockets Server Side 3. Set up input and output streams. Methods getinputstream and getoutputstream of class Socket are used to get references to streams associated with the socket returned in step 2. These streams will be used for communication with the client that has just made connection. For a non-gui application, we can wrap a Scanner object around the InputStream object returned by method getinputstream, in order to obtain string-orientated input (just as we would do with input from the standard input stream, System.in). For example: Scanner InFromClient= new Scanner(link.getInputStream()); Similarly, we can wrap a PrintWriter object around the OutputStream object returned by method getoutputstream. Supplying the PrintWriter constructor with a second argument of true will cause the output buffer to be flushed for every call of println (which is usually desirable). For example: PrintWriter OutToclient= new PrintWriter(link.getOutputStream(),true); 23

24 TCP Sockets Server Side 4. Send and receive data. Having set up our Scanner and PrintWriter objects, sending and receiving data is very straightforward. We simply use method nextline for receiving data and method println for sending data, just as we might do for console I/O. For example: OutToClient.println("Awaiting data..."); String input = InFromClient.nextLine(); 5. Close the connection (after completion of the dialogue). This is achieved via method close of class Socket. For example: link.close(); 24

25 TCP Sockets Client Side Setting up the corresponding client involves four steps Establish a connection to the server. We create a Socket object, supplying its constructor with the following two arguments: the server's IP address (of type InetAddress); the appropriate port number for the service. (The port number for server and client programs must be the same, of course!) For simplicity's sake, we shall place client and server on the same host, which will allow us to retrieve the IP address by calling static method getlocalhost of class InetAddress. For example: Socket link = new Socket(InetAddress.getLocalHost(),1234); 25

26 TCP Sockets Client Side 2. Set up input and output streams. These are set up in exactly the same way as the server streams were set up (by calling methods getinputstream and getoutputstream of the Socket object that was created in step 2). 3. Send and receive data. The Scanner object at the client end will receive messages sent by the PrintWriter object at the server end, while the PrintWriter object at the client end will send messages that are received by the Scanner object at the server end (using methods nextline and println respectively). 4. Close the connection. This is exactly the same as for the server process (using method close of class Socket). 26

27 Example 1 TCPEchoServer_V1.java In this simple example, the server: will accept messages from the client and echo back each message. The main protocol for this service is that client and server must alternate between sending and receiving (with the client initiating the process with its opening message, of course). The client, of course, must wait for the final message from the server before closing the connection at its own end. 27

28 Example 1 TCPEchoServer_V1.java Since an IOException may be generated by any of the socket operations, ONE OR MORE try blocks MUST be used. Rather than have one large try block (with no variation in the error message produced and, consequently, no indication of precisely what operation caused the problem), it is probably good practice to have the opening of the port and the dialogue with the client in separate try blocks. It is also good practice to place the closing of the socket in a finally clause, so that, whether an exception occurs or not, the socket will be closed (unless, of course, the exception is generated when actually closing the socket, but there is nothing we can do about that). Since the finally clause will need to know about the Socket object, we shall have to declare this object within a scope that covers both the try block handling the dialogue and the finally block. Thus, step 2 shown above will be broken up into separate declaration and assignment. In our example program, this will also mean that the Socket object will have to be explicitly initialized to null (as it will not be a global variable). 28

29 Example 1 TCPEchoServer_V1.java Since a server offering a public service would keep running indefinitely, the call to method handleclient in our example has been placed inside an infinite loop, thus: 29

30 Example 1 TCPEchoServer_V1.java 30

31 31

32 Example 1 TCPEchoClient_V1.java The client program for our example is shown next. In addition to an input stream to accept messages from the server, our client program will need to set up an input stream (as another Scanner object) to accept user messages from the keyboard. 32

33 33

34 Example 1 34

35 Example 2 Modify the server process in order to echo back each message but in capital letters. 35

36 Example 3 Write the client and the server processes that implement the following ECHO protocol: The server must accepts ONLY 3 messages from a client. The server before echoing back each message converts the message to uppercase, appends the date and the number of each message as shown in the following screenshots: 36

37 Example 4 TCPEchoServer.java In this simple example, the server will accept messages from the client and will keep count of those messages, echoing back each (numbered) message. The main protocol for this service is that client and server must alternate between sending and receiving (with the client initiating the process with its opening message, of course). The only details that remain to be determined are the means of indicating when the dialogue is to cease and what final data (if any) should be sent by the server. For this simple example, the string "***CLOSE***" will be sent by the client when it wishes to close down the connection. When the server receives this message, it will confirm the number of preceding messages received and then close its connection to this client. The client, of course, must wait for the final message from the server before closing the connection at its own end. 37

38 38

39 39

40 The Socket Class The Constructors: public Socket(String host, int port) throws UnknownHostException, IOException public Socket(InetAddress host, int port) throws IOException Getting Information About a Socket public int getport( ) public int getlocalport( ) public InetAddress getlocaladdress( ) public InputStream getinputstream( ) throws IOException public OutputStream getoutputstream( ) throws IOException Closing the Socket public void close( ) throws IOException 40

41 The Socket Class It is true that a socket closes automatically when one of its two streams closes, when the program ends, or when it's garbage collected. However, it is a bad practice to assume that the system will close sockets for you, especially for programs that may run for an indefinite period of time. In a socket-intensive program like a web browser, the system may well hit its maximum number of open sockets before the garbage collector kicks in. 41

42 The ServerSocket Class The Constructors public ServerSocket(int port) throws BindException, IOException public ServerSocket(int port, int queuelength) throws BindException, IOException public ServerSocket(int port, int queuelength, InetAddress bindaddress) throws IOException public ServerSocket( ) throws IOException // Java 1.4 Accepting and Closing Connections public Socket accept( ) throws IOException public void close( ) throws IOException The get Methods public InetAddress getinetaddress( ) public int getlocalport( ) 42

Networking and Security

Networking and Security Chapter 03 Networking and Security Mr. Nilesh Vishwasrao Patil Government Polytechnic Ahmednagar Socket Network socket is an endpoint of an interprocess communication flow across a computer network. Sockets

More information

Socket 101 Excerpt from Network Programming

Socket 101 Excerpt from Network Programming Socket 101 Excerpt from Network Programming EDA095 Nätverksprogrammering Originals by Roger Henriksson Computer Science Lund University Java I/O Streams Stream (swe. Ström) - A stream is a sequential ordering

More information

JAVA - NETWORKING (SOCKET PROGRAMMING)

JAVA - NETWORKING (SOCKET PROGRAMMING) JAVA - NETWORKING (SOCKET PROGRAMMING) http://www.tutorialspoint.com/java/java_networking.htm Copyright tutorialspoint.com The term network programming refers to writing programs that execute across multiple

More information

CSCD 330 Network Programming Spring 2018

CSCD 330 Network Programming Spring 2018 CSCD 330 Network Programming Spring 2018 Lecture 6 Application Layer Socket Programming in Java Reading for Java Client/Server see Relevant Links Some Material in these slides from J.F Kurose and K.W.

More information

JAVA SOCKET PROGRAMMING

JAVA SOCKET PROGRAMMING JAVA SOCKET PROGRAMMING WHAT IS A SOCKET? Socket The combination of an IP address and a port number. (RFC 793 original TCP specification) The name of the Berkeley-derived application programming interfaces

More information

Outlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics

Outlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics G52APR Application programming Networking in Java Michael Li http://www.cs.nott.ac.uk/~jwl/g52apr Outlines Networking basics Network architecture IP address and port Server-client model TCP and UDP protocol

More information

Distributed Systems Recitation 2. Tamim Jabban

Distributed Systems Recitation 2. Tamim Jabban 15-440 Distributed Systems Recitation 2 Tamim Jabban Project 1 Involves creating a Distributed File System (DFS) Released yesterday When/If done with PS1, start reading the handout Today: Socket communication!

More information

SERVER/CLIENT NETWORKING AT JAVA PLATFORM

SERVER/CLIENT NETWORKING AT JAVA PLATFORM SERVER/CLIENT NETWORKING AT JAVA PLATFORM Vibhu Chinmay, Shubham Sachdeva Student (B.tech5 th sem) Department of Electronics and Computers Engineering Dronacharya College of Engineering, Gurgaon-123506,

More information

Distributed Systems Recitation 2. Tamim Jabban

Distributed Systems Recitation 2. Tamim Jabban 15-440 Distributed Systems Recitation 2 Tamim Jabban Agenda Communication via Sockets in Java (this enables you to complete PS1 and start P1 (goes out today!)) Multi-threading in Java Coding a full Client-Server

More information

Lecture 3. Java Socket Programming. TCP, UDP and URL

Lecture 3. Java Socket Programming. TCP, UDP and URL Lecture 3 TCP, UDP and URL 1 Java Sockets Programming The package java.net provides support for sockets programming (and more). Typically you import everything defined in this package with: import java.net.*;

More information

Info 408 Distributed Applications programming 2 nd semester of Credits: 5 Lecturer: Dr. Antoun Yaacoub

Info 408 Distributed Applications programming 2 nd semester of Credits: 5 Lecturer: Dr. Antoun Yaacoub Lebanese University Faculty of Science I Master 1 degree Computer Sciences Info 408 Distributed Applications programming 2 nd semester of 2017-2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub Datagram (UDP)

More information

OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING 1 OBJECT ORIENTED PROGRAMMING Lecture 14 Networking Basics Outline 2 Networking Basics Socket IP Address DNS Client/Server Networking Class & Interface URL Demonstrating URL Networking 3 Java is practically

More information

Networking with java (socket programming) a brief study

Networking with java (socket programming) a brief study REVIEWS COMPUTER ENGINEERING Discovery Engineering, Volume 2, Number 7, October 2013 ISSN 2320 6675 EISSN 2320 6853 Discovery Engineering REVIEWS COMPUTER ENGINEERING discovery Engineering Networking with

More information

CS 355. Computer Networking. Wei Lu, Ph.D., P.Eng.

CS 355. Computer Networking. Wei Lu, Ph.D., P.Eng. CS 355 Computer Networking Wei Lu, Ph.D., P.Eng. Chapter 2: Application Layer Overview: Principles of network applications? Introduction to Wireshark Web and HTTP FTP Electronic Mail: SMTP, POP3, IMAP

More information

Advanced Java Programming. Networking

Advanced Java Programming. Networking Advanced Java Programming Networking Eran Werner and Ohad Barzilay Tel-Aviv University Advanced Java Programming, Spring 2006 1 Overview of networking Advanced Java Programming, Spring 2006 2 TCP/IP protocol

More information

Unit 9: Network Programming

Unit 9: Network Programming Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 9: Network Programming 1 1. Background 2. Accessing

More information

Previous lecture: threads G51PRG: Introduction to Programming Second semester Lecture 12 URL

Previous lecture: threads G51PRG: Introduction to Programming Second semester Lecture 12 URL Previous lecture: threads G51PRG: Introduction to Programming Second semester Lecture 12 What is a thread Why use multiple threads Issues and problems involved Java threads Natasha Alechina School of Computer

More information

Networking: IPv6, UDP and TCP. Network Programming in Java UDP and TCP

Networking: IPv6, UDP and TCP. Network Programming in Java UDP and TCP Networking: IPv6, UDP and TCP Network Programming in Java UDP and TCP SCOMRED, November 2018 Instituto Superior de Engenharia do Porto (ISEP) Departamento de Engenharia Informática(DEI) SWitCH Computing

More information

Introduction to Sockets 9/25/14

Introduction to Sockets 9/25/14 Introduction to Sockets 9/25/14 81 Remote communication Inter-process communication is at the heart of all distributed systems Using the network protocol stack on a node is the only way to communicate

More information

AJP: Chapter 2 Networking: 18 marks

AJP: Chapter 2 Networking: 18 marks AJP: Chapter 2 Networking: 18 marks Syllabus 2.1 Basics Socket overview, client/server, reserved sockets, proxy servers, internet addressing. 2.2 Java & the Net The networking classes & interfaces 2.3

More information

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication JAVA Network API To be discussed 1 - java.net... 1 2 - Connection-Oriented vs. Connectionless Communication... 1 3 - Connectionless:... 1 4 - Networking Protocols... 2 5 - Sockets... 2 6 - Multicast Addressing...

More information

Java Support for developing TCP Network Based Programs

Java Support for developing TCP Network Based Programs Java Support for developing TCP Network Based Programs 1 How to Write a Network Based Program (In Java) As mentioned, we will use the TCP Transport Protocol. To communicate over TCP, a client program and

More information

Communication in Distributed Systems: Sockets Programming. Operating Systems

Communication in Distributed Systems: Sockets Programming. Operating Systems Communication in Distributed Systems: Sockets Programming Operating Systems TCP/IP layers Layers Message Application Transport Internet Network interface Messages (UDP) or Streams (TCP) UDP or TCP packets

More information

Java Networking (sockets)

Java Networking (sockets) Java Networking (sockets) Rui Moreira Links: http://java.sun.com/docs/books/tutorial/networking/toc.html#sockets http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets_p.html Networking Computers

More information

Distributed Systems. 3. Access to the Transport Layer. Werner Nutt

Distributed Systems. 3. Access to the Transport Layer. Werner Nutt Distributed Systems 3. Access to the Transport Layer Werner Nutt 1 Access to the Transport Layer Processes issue requests to the transport layer (i.e., the application takes the initiative, not the transport

More information

Pieter van den Hombergh Richard van den Ham. March 17, 2018

Pieter van den Hombergh Richard van den Ham. March 17, 2018 : Network : Network, Object Pieter van den Hombergh Richard van den Ham Fontys Hogeschool voor Techniek en Logistiek March 17, 2018 /FHTenL : Network March 17, 2018 1/21 Topics, Object Some everyday life

More information

Interprocess Communication

Interprocess Communication Interprocess Communication Nicola Dragoni Embedded Systems Engineering DTU Informatics 4.2 Characteristics, Sockets, Client-Server Communication: UDP vs TCP 4.4 Group (Multicast) Communication The Characteristics

More information

SOCKETS. COMP750 Distributed Systems

SOCKETS. COMP750 Distributed Systems SOCKETS COMP750 Distributed Systems Sockets The Socket library is a traditional Application Program Interface (API) to the transport layer. Sockets were originally implemented in Unix systems and have

More information

Unit 1 Java Networking

Unit 1 Java Networking Q1. What is Server Socket? Discuss the difference between the Socket and ServerSocket class. The ServerSocket class (java.net) can be used to create a server socket. This object is used to establish communication

More information

TCP connections. Fundamentals of Internet Connections Objectives. Connect to an Echo port. java.net.socket

TCP connections. Fundamentals of Internet Connections Objectives. Connect to an Echo port. java.net.socket Objectives TCP connections To understand programming of clients that connect to servers via TCP To understand the basics of programming of servers that accept TCP connections To practice programming of

More information

CSCD 330 Network Programming Spring 2018

CSCD 330 Network Programming Spring 2018 CSCD 330 Network Programming Spring 2018 Lecture 7 Application Layer Socket Programming in Java Reading: Chapter 2, Java links Relevant Links page Some Material in these slides from J.F Kurose and K.W.

More information

Basic Java Network Programming. CS211 July 30 th, 2001

Basic Java Network Programming. CS211 July 30 th, 2001 Basic Java Network Programming CS211 July 30 th, 2001 The Network and OSI Model IP Header TCP Header TCP/IP: A Paradox TCP Connection Oriented and Connectionless Protocols Reliable: no loss, or duplication,

More information

CSCD 330 Network Programming Winter 2019

CSCD 330 Network Programming Winter 2019 CSCD 330 Network Programming Winter 2019 Lecture 7 Application Layer Socket Programming in Java Reading: Chapter 2, Java links Relevant Links page Some Material in these slides from J.F Kurose and K.W.

More information

Lab 10: Sockets 12:00 PM, Apr 4, 2018

Lab 10: Sockets 12:00 PM, Apr 4, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lab 10: Sockets 12:00 PM, Apr 4, 2018 Contents 1 The Client-Server Model 1 1.1 Constructing Java Sockets.................................

More information

Networking Basics. network communication.

Networking Basics. network communication. JAVA NETWORKING API Networking Basics When you write Java programs that communicate over the network, you are programming at the application layer. Typically, you don't need to concern yourself with the

More information

Introduction to Socket Programming

Introduction to Socket Programming Introduction to Socket Programming (Advanced Computer Networks) By Priyank Shah NET ID : pss160530 A Simple Question What are Sockets? Sockets are communication points on the same or different computers

More information

Java Input/Output. 11 April 2013 OSU CSE 1

Java Input/Output. 11 April 2013 OSU CSE 1 Java Input/Output 11 April 2013 OSU CSE 1 Overview The Java I/O (Input/Output) package java.io contains a group of interfaces and classes similar to the OSU CSE components SimpleReader and SimpleWriter

More information

CS 351 Design of Large Programs Sockets Example

CS 351 Design of Large Programs Sockets Example CS 351 Design of Large Programs Sockets Example Brooke Chenoweth University of New Mexico Spring 2019 Socket Socket(String host, int port) InputStream getinputstream() OutputStream getoutputstream() void

More information

Redesde Computadores(RCOMP)

Redesde Computadores(RCOMP) Redesde Computadores(RCOMP) Theoretical-Practical (TP) Lesson 07 2016/2017 Berkeley sockets API, C and Java. Basic functions/methods for TCP applications. TCP client and server. Asynchronous reception.

More information

Networks and Internet Programming

Networks and Internet Programming Networks and Internet Programming Transmission Control Protocol 1 Outline Overview. Advantages of TCP Over UDP. Communication between Applications Using Ports. Socket Operations. TCP and the Client/Server

More information

Ch.4 Internet Addresses

Ch.4 Internet Addresses CSB541 Network Programming 網路程式設計 Ch.4 Internet Addresses 吳俊興國立高雄大學資訊工程學系 Outline 4.1 The InetAddress Class 4.2 Inet4Address and Inet6Address 4.3 The NetworkInterface Class 4.4 Some Useful Programs 2 Internet

More information

Chapter 2 Application Layer

Chapter 2 Application Layer Chapter 2 Application Layer A note on the use of these ppt slides: We re making these slides freely available to all (faculty, students, readers). They re in PowerPoint form so you can add, modify, and

More information

Transport layer protocols. Lecture 15: Operating Systems and Networks Behzad Bordbar

Transport layer protocols. Lecture 15: Operating Systems and Networks Behzad Bordbar Transport layer protocols Lecture 15: Operating Systems and Networks Behzad Bordbar 78 Interprocess communication Synchronous and asynchronous comm. Message destination Reliability Ordering Client Server

More information

Principles of Software Construction. Introduction to networks and distributed systems School of Computer Science

Principles of Software Construction. Introduction to networks and distributed systems School of Computer Science Principles of Software Construction Introduction to networks and distributed systems Josh Bloch Charlie Garrod School of Computer Science 1 Administrivia Homework 5 Best Frameworks available tonight Or

More information

Internet Protocol. Chapter 5 Protocol Layering. Juho Kim Graduate School of Information & Technology Sogang University

Internet Protocol. Chapter 5 Protocol Layering. Juho Kim Graduate School of Information & Technology Sogang University Internet Protocol Chapter 5 Protocol Layering Juho Kim Graduate School of Information & Technology Sogang University Department of of Computer Science and and Engineering, Sogang University Page 1 CAD

More information

TRIBHUVAN UNIVERSITY INSTITUTE OF ENGINEERING PULCHOWK CAMPUS DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING. A Report On MARRAIGE

TRIBHUVAN UNIVERSITY INSTITUTE OF ENGINEERING PULCHOWK CAMPUS DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING. A Report On MARRAIGE TRIBHUVAN UNIVERSITY INSTITUTE OF ENGINEERING PULCHOWK CAMPUS DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING A Report On MARRAIGE Submitted To: Department of Electronics and Computer Engineering Pulchowk

More information

COMP 213. Advanced Object-oriented Programming. Lecture 20. Network Programming

COMP 213. Advanced Object-oriented Programming. Lecture 20. Network Programming COMP 213 Advanced Object-oriented Programming Lecture 20 Network Programming Network Programming A network consists of several computers connected so that data can be sent from one to another. Network

More information

Redes de Computadores (RCOMP)

Redes de Computadores (RCOMP) Redes de Computadores (RCOMP) Theoretical-Practical (TP) Lesson 07 2017/2018 Berkeley sockets API, C and Java. Basic functions/methods for TCP applications. TCP client and server. Asynchronous reception.

More information

Jan Graba. An Introduction to Network Programming with Java. Java 7 Compatible Third Edition.

Jan Graba. An Introduction to Network Programming with Java. Java 7 Compatible Third Edition. Jan Graba An Introduction to Network Programming with Java Java 7 Compatible Third Edition An Introduction to Network Programming with Java Jan Graba An Introduction to Network Programming with Java Java

More information

Chapter 9: UDP sockets & address conversion function

Chapter 9: UDP sockets & address conversion function Chapter 9: UDP sockets & address conversion function 9.1 Elementary UDP sockets:- Introduction to UDP sockets UDP is connectionless, unreliable, datagram protocol TCP is connection-oriented, reliable byte

More information

Lecture 3: Socket Programming

Lecture 3: Socket Programming Lecture 3: Socket Programming Prof. Shervin Shirmohammadi SITE, University of Ottawa Fall 2005 CEG4183/ELG4183 3-1 Sockets From a logical perspective, a Socket is a communication end point. It is not a

More information

What HTTP is : it forms elements (.html..xml) with programs (processes) running on the server (e.g. java) and on clients (e.g. javascript), cookies).

What HTTP is : it forms elements (.html..xml) with programs (processes) running on the server (e.g. java) and on clients (e.g. javascript), cookies). 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 interpreted by the browser What HTTP is : it forms

More information

protocols September 15,

protocols  September 15, Contents SCI 351 4 Protocols, WWW Internet applications WWW, document technology Lennart Herlaar Original slides by Piet van Oostrum September 15, 2003 SCI351-4 1 X SCI351-4 1 X Internet applications How

More information

Internet Technology 2/7/2013

Internet Technology 2/7/2013 Sample Client-Server Program Internet Technology 02r. Programming with Sockets Paul Krzyzanowski Rutgers University Spring 2013 To illustrate programming with TCP/IP sockets, we ll write a small client-server

More information

Chapter 11. Application-Layer Elements Ports

Chapter 11. Application-Layer Elements Ports Chapter 11 Application-Layer Elements 11.1 Ports........................... 93 11.2 Sockets.......................... 95 11.2.1 Socket Domains, Types and Protocols....... 95 11.2.2 Operations on Sockets................

More information

Simple Java Input/Output

Simple Java Input/Output Simple Java Input/Output Prologue They say you can hold seven plus or minus two pieces of information in your mind. I can t remember how to open files in Java. I ve written chapters on it. I ve done it

More information

CSC 4900 Computer Networks: P2P and Sockets

CSC 4900 Computer Networks: P2P and Sockets CSC 4900 Computer Networks: P2P and Sockets Professor Henry Carter Fall 2017 Recap SMTP is the language that mail servers use to exchange messages. SMTP is push-based... why? You can run SMTP from a telnet

More information

Network Programming Benoît Garbinato

Network Programming Benoît Garbinato Network Programming Benoît Garbinato 1 Network programming Network programming is not distributed programming (somewhat lower-level) They both rely on: computers as processing & storage resources a network

More information

CS 2113 Software Engineering

CS 2113 Software Engineering CS 2113 Software Engineering Java 6: File and Network IO https://github.com/cs2113f18/template-j-6-io.git Professor Tim Wood - The George Washington University Project 2 Zombies Basic GUI interactions

More information

Principles, Models and Applications for Distributed Systems M

Principles, Models and Applications for Distributed Systems M Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models and Applications for Distributed Systems M Lab assignment 2 (worked-out) Connectionless Java Sockets Luca Foschini 2010/2011 Exercise

More information

ECS-503 Object Oriented Techniques

ECS-503 Object Oriented Techniques UNIT-4 Part-2 ECS-503 Object Oriented Techniques CHAPTER 16 String Handling Java implements strings as objects of type String. Implementing strings as built-in objects allows Java to provide a full complement

More information

Communication Paradigms

Communication Paradigms Communication Paradigms Nicola Dragoni Embedded Systems Engineering DTU Compute 1. Interprocess Communication Direct Communication: Sockets Indirect Communication: IP Multicast 2. High Level Communication

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

More information

Networking. Lecture 25 ish? COP 3252 Summer July 11, 2017

Networking. Lecture 25 ish? COP 3252 Summer July 11, 2017 Networking Lecture 25 ish? COP 3252 Summer 2017 July 11, 2017 Open-Read/Write-Close The Unix I/O system follows a paradigm usually referred to as Open-Read/Write-Close. Before a program/process can perform

More information

Introduction to Java.net Package. CGS 3416 Java for Non Majors

Introduction to Java.net Package. CGS 3416 Java for Non Majors Introduction to Java.net Package CGS 3416 Java for Non Majors 1 Package Overview The package java.net contains class and interfaces that provide powerful infrastructure for implementing networking applications.

More information

Chapter 2 Applications and

Chapter 2 Applications and Chapter 2 Applications and Layered Architectures Sockets Socket API API (Application Programming Interface) Provides a standard set of functions that can be called by applications Berkeley UNIX Sockets

More information

CS2 Advanced Programming in Java note 8

CS2 Advanced Programming in Java note 8 CS2 Advanced Programming in Java note 8 Java and the Internet One of the reasons Java is so popular is because of the exciting possibilities it offers for exploiting the power of the Internet. On the one

More information

Info 408 Distributed Applications programming 2 nd semester of Credits: 5 Lecturer: Antoun Yaacoub Ph.D.

Info 408 Distributed Applications programming 2 nd semester of Credits: 5 Lecturer: Antoun Yaacoub Ph.D. Lebanese University Faculty of Sciences I Master 1 degree Computer Sciences Info 408 Distributed Applications programming 2 nd semester of 2018-2019 Credits: 5 Lecturer: Antoun Yaacoub Ph.D. Info 408 Distributed

More information

CS September 2017

CS September 2017 Machine vs. transport endpoints IP is a network layer protocol: packets address only the machine IP header identifies source IP address, destination IP address Distributed Systems 01r. Sockets Programming

More information

Lecture 11.1 I/O Streams

Lecture 11.1 I/O Streams 21/04/2014 Ebtsam AbdelHakam 1 OBJECT ORIENTED PROGRAMMING Lecture 11.1 I/O Streams 21/04/2014 Ebtsam AbdelHakam 2 Outline I/O Basics Streams Reading characters and string 21/04/2014 Ebtsam AbdelHakam

More information

CISC 4700 L01 Network & Client-Server Programming Spring Harold, Chapter 4: Internet Addresses

CISC 4700 L01 Network & Client-Server Programming Spring Harold, Chapter 4: Internet Addresses CISC 4700 L01 Network & Client-Server Programming Spring 2016 Harold, Chapter 4: Internet Addresses IPv4 address: four bytes (150.108.64.64) IPv6 address: sixteen bytes (2001:0250:02FF:0210:0250:8BFF:FEDE:67C8)

More information

Scheme G Sample Question Paper Unit Test 2

Scheme G Sample Question Paper Unit Test 2 Scheme G Sample Question Paper Unit Test 2 Course Name: Computer Engineering Group Course Code: CO/CD/CM/CW/IF Semester: Sixth Subject Title: Advanced Java Programming Marks: 25 Marks 17625 ---------------------------------------------------------------------------------------------------------------------------

More information

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Starting Out with Java: From Control Structures Through Objects Sixth Edition Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 11 I/O File Input and Output Reentering data all the time could get tedious for the user. The data can be saved to

More information

Java A.1 TCP/IP TCP. TCP_RO.java import java.net.*; import java.io.*;

Java A.1 TCP/IP TCP. TCP_RO.java import java.net.*; import java.io.*; II A p.1 A Java C Java TCP/IP TCP/IP A.1 A.1.1 TCP TCP_RO.java public class TCP_RO { public static void main(string[] argv) { Socket readsocket = new Socket(argv[0], Integer.parseInt(argv[1])); InputStream

More information

Distributed Programming - Sockets

Distributed Programming - Sockets Distributed Programming - Sockets Piet van Oostrum May 25, 2009 Concurrency In praktische situaties krijgen we concurrency door: Processen Threads Interrupts (alleen intern in het O.S.) Processen Onafhankelijke

More information

Object-Oriented Programming in Java

Object-Oriented Programming in Java CSCI/CMPE 3326 Object-Oriented Programming in Java 1. Socket Programming Dongchul Kim Department of Computer Science University of Texas Rio Grande Valley Two types of TCP Socket java.net.serversocket

More information

Tommy Färnqvist, IDA, Linköping University

Tommy Färnqvist, IDA, Linköping University Lecture 4 Threads and Networking in Java TDDC32 Lecture notes in Design and Implementation of a Software Module in Java 23 January 2013 Tommy Färnqvist, IDA, Linköping University 4.1 Lecture Topics Contents

More information

Sockets: Network io HOM DOS HVD HEE. Sockets, Object Streams and Serialization. Sockets. Sockets: Network io HOM DOS HVD HEE

Sockets: Network io HOM DOS HVD HEE. Sockets, Object Streams and Serialization. Sockets. Sockets: Network io HOM DOS HVD HEE : Network : Network ieter van den Hombergh hijs Dorssers ichard van den Ham Uwe van Heesch, bject Fontys Hogeschool voor echniek en Logistiek April 22, 2016 /FHenL : Network April 22, 2016 1/19 opics :

More information

Topic 10: Network Programming

Topic 10: Network Programming Topic 10: Network Programming Client-Server Model Host and Port Socket Implementing Client Implementing Server Implementing Server for Multiple Clients Client-Server Model Clients Request a server to provide

More information

Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub

Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub Lebanese University Faculty of Sciences I Master 1 degree Computer Sciences Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub 2 Multithreading

More information

CS 251 Intermediate Programming Java I/O Streams

CS 251 Intermediate Programming Java I/O Streams CS 251 Intermediate Programming Java I/O Streams Brooke Chenoweth University of New Mexico Spring 2018 Basic Input/Output I/O Streams mostly in java.io package File I/O mostly in java.nio.file package

More information

Week 13 Lab - Exploring Connections & Remote Execution

Week 13 Lab - Exploring Connections & Remote Execution Week 13 Lab - Exploring Connections & Remote Execution COSC244 & TELE202 1 Assessment This lab is worth 0.5%. The marks are awarded for completing the programming exercise and answering the questions.

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 30 April 4, 2018 I/O & Histogram Demo Chapters 28 HW7: Chat Server Announcements No penalty for late submission by tomorrow (which is a HARD deadline!)

More information

31 Network Programming

31 Network Programming 31 Network Programming Network / Inter-Network OODS 1997-2000 Michael Golm Network Programming 31.218 31.1 Host Addressing: InetAddress IP addresses: DNS form: www4.informatik.uni-erlangen.de "dotted quad"

More information

Introduction to Sockets

Introduction to Sockets Introduction to Sockets Sockets in Java 07/02/2012 EPL 602 1 Socket programming Goal: learn how to build client/server application that communicate using sockets Socket API o introduced in BSD4.1 UNIX,

More information

Dining philosophers (cont)

Dining philosophers (cont) Administrivia Assignment #4 is out Due Thursday April 8, 10:00pm no late assignments will be accepted Sign up in labs this week for a demo time Office hour today will be cut short (11:30) Another faculty

More information

Full file at

Full file at Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

More information

Chapter 2 outline. 2.1 Principles of app layer protocols

Chapter 2 outline. 2.1 Principles of app layer protocols Chapter 2 outline 2.1 Principles of app layer protocols clients and servers app requirements 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 Socket programming with TCP 2.7 Socket

More information

Writing a Protocol Handler

Writing a Protocol Handler Writing a Protocol Handler A URL object uses a protocol handler to establish a connection with a server and perform whatever protocol is necessary to retrieve data. For example, an HTTP protocol handler

More information

Chapter 2: outline. 2.1 principles of network applications. 2.6 P2P applications 2.7 socket programming with UDP and TCP

Chapter 2: outline. 2.1 principles of network applications. 2.6 P2P applications 2.7 socket programming with UDP and TCP Chapter 2: outline 2.1 principles of network applications app architectures app requirements 2.2 Web and HTTP 2.3 FTP 2.4 electronic mail SMTP, POP3, IMAP 2.5 DNS 2.6 P2P applications 2.7 socket programming

More information

Chapter 2 Application Layer

Chapter 2 Application Layer Internet and Intranet Protocols and Applications Lecture 4: Application Layer 3: Socket Programming Spring 2006 Arthur Goldberg Computer Science Department New York University artg@cs.nyu.edu Chapter 2

More information

CS18000: Programming I

CS18000: Programming I CS18000: Programming I File I/O 22 March, 2010 Prof. Chris Clifton Goal: Make Data Useful Beyond Program Execution Program data stored in variables Okay, a little more than that Arrays Linked data structures

More information

World Scientific Research Journal (WSRJ) ISSN: The Implementation of Tcp Socket Programming based on Java

World Scientific Research Journal (WSRJ) ISSN: The Implementation of Tcp Socket Programming based on Java World Scientific Research Journal (WSRJ) ISSN: 2472-3703 www.wsr-j.org The Implementation of Tcp Socket Programming based on Java Deen Chen Computer Science Department, North China Electric Power University,

More information

Socket Programming(TCP & UDP) Sanjay Chakraborty

Socket Programming(TCP & UDP) Sanjay Chakraborty Socket Programming(TCP & UDP) Sanjay Chakraborty Computer network programming involves writing computer programs that enable processes to communicate with each other across a computer network. The endpoint

More information

Lab 2: File Input and Output

Lab 2: File Input and Output Lab 2: File Input and Output This lab introduces how to handle files as both input and output. We re coming back to Tracery (which you implemented in Lab 1) with this assignment but instead of always reading

More information

Sri Vidya College of Engineering & Technology Question Bank

Sri Vidya College of Engineering & Technology Question Bank 1. What is exception? UNIT III EXCEPTION HANDLING AND I/O Part A Question Bank An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program s instructions.

More information

Sockets: Network io HOM HVD. Sockets, Object Streams and Serialization. Sockets. Sockets: Network io HOM HVD

Sockets: Network io HOM HVD. Sockets, Object Streams and Serialization. Sockets. Sockets: Network io HOM HVD : Network : Network, bject ieter van den Hombergh ichard van den Ham Fontys Hogeschool voor echniek en Logistiek March 17, 2018 /FHenL : Network March 17, 2018 1/21 opics, bject Some everyday life sockets:

More information

CPSC 441 Tutorial TCP Server. Department of Computer Science University of Calgary

CPSC 441 Tutorial TCP Server. Department of Computer Science University of Calgary CPSC 441 Tutorial TCP Server Department of Computer Science University of Calgary TCP Socket Client Server Connection Request Server Listening on welcoming socket Client Socket Server Socket Data Simple

More information

Connecting to a Server Implementing Servers Making URL Connections Advanced Socket Programming

Connecting to a Server Implementing Servers Making URL Connections Advanced Socket Programming Course Name: Advanced Java Lecture 11 Topics to be covered Connecting to a Server Implementing Servers Making URL Connections Advanced Socket Programming Introduction Internet and WWW have emerged as global

More information

Web Server Project. Tom Kelliher, CS points, due May 4, 2011

Web Server Project. Tom Kelliher, CS points, due May 4, 2011 Web Server Project Tom Kelliher, CS 325 100 points, due May 4, 2011 Introduction (From Kurose & Ross, 4th ed.) In this project you will develop a Web server in two steps. In the end, you will have built

More information