Java 6. Network programming
|
|
- Anis Burke
- 5 years ago
- Views:
Transcription
1 Java 6 Network programming
2 Internet Protocol (IP) IP addresses 32-bit number used to identify machines on the network e.g., is the IP address of always refers to the current machine (also called localhost) Datagram packet of data of limited size up to bytes, but only 1500 bytes on Ethernet network IP defines how datagrams sent across the network involves routing through intermediate machines IP is an unreliable protocol datagrams may be lost, arrive out of order or duplicated
3 Networking basics Programs running on computers connected over a network communicate using either: TCP (Transmission Control Protocol) UDP (User Datagram Protocol) You will mostly write programs that operate at the Application layer Use the classes in the java.net package To decide which classes to use, need to choose between TCP and UDP
4 TCP TCP is a connection-based protocol that provides a reliable, bi-directional flow of data between two computers (or two programs running on the same computer) TCP guarantees that all data sent from one end of a TCP connection arrives at the other end in the right order If packets are lost, they are re-sent Ordering of packets checked at the receiving end of the connection Good for applications that require a reliable connection, such as HTTP, FTP, Telnet
5 UDP UDP sends independent packets of data called datagrams from one computer (or program) to another UDP does not guarantee that data will arrive at the destination in the same order in which it was sent UDP does not guarantee that the data will arrive at the destination at all! Unlike TCP, UDP is not connection-based UDP is faster than TCP because there is no error-correction UDP is good for applications that require very fast data transfer but do not require 100% reliability, such as Video and audio streaming Time server If signal fails to arrive, then it will be out-of-date anyway so does not need to be resent new signal needs to be sent Ping tests connection quality by counting how many packets are lost
6 Sockets and ports End points of a TCP connection are called sockets Each socket is associated with a particular port on a particular machine Port is identified by a 16-bit integer between 0 and allows single machine to have many simultaneous connections, each coming into a different port Ports : well-known ports assigned to server applications executed by privileged processes (e.g., UNIX root user), e.g., port 80 reserved for HTTP communication ports 20 and 21 reserved for FTP servers port 25 reserved for SMTP servers port 443 reserved for HTTPS Ports : registered ports e.g., port 8080 reserved as alternative to 80 for running a web server using ordinary user privileges Ports : dynamic or private ports can be freely used by any client or server program Browsers obtain ports for their TCP sockets arbitrarily among unused nonwell-known ports
7 Understanding Ports All the data coming into a machine might enter through a single physical network connection However, data might be intended for different applications (e.g., http server, ftp server, smtp server) Each application that receives data through the network will be listening for the data on a specific port TCP and UDP use ports to map incoming data to a particular process running on a computer In UDP, each datagram sent over the network will be labelled with the 32-bit IP address of the machine that it is supposed to go to and the 16-bit port number associated with the program (application) that will use the data In TCP, a server application binds a socket to a specific port number and then the server will receive all data sent over a connection to that port
8 Which is better for Client/Server Apps? UDP (Datagram) No Connection Setup Time 64 kilobyte limit per location Unreliable (packets could arrive out of order) TCP (Stream) Connection Setup Time No limit Reliable (packets always arrive in order)
9 In Summary TCP is useful for implementing network services, such as remote login (rlogin, telnet) and file transfer (FTP), which require data of indefinite length to be transferred. UDP is less complex and incurs fewer overheads. It is best for implementing client/server applications in distributed systems built over local area networks (LANs).
10 java.net classes Java programs can use TCP or UDP TCP classes: URL URLConnection Socket ServerSocket UDP classes DatagramPacket DatagramSocket MulticastSocket
11 URLs (Uniform Resource Locators) URL is a reference to a resource (file, program, etc.) on the internet A URL is represented in Java by the java.net.url class In http is protocol or scheme is resource name HTTP is just one of many protocols used for transferring data over the internet (other examples of protocols are ftp, smtp, file, gopher, news) Resource name is complete name of resource format depends on protocol typically contains host name name of machine filename pathname to file on machine port number optional number of port to connect to reference refers to named anchor identifying specific location in a file (optional)
12 Creating URLs in Java To create a URL object from an absolute URL string, use the URL constructor as follows: URL url = new URL( ); Sometimes in HTML, only the relative URL is given in a link if the target file is in the same directory as the referring file e.g., if the following tag <a href= papers.php >Publications</a> appears in /index.php, then the link will be to the file that has the absolute address To create a URL object from a relative URL string, first define a URL object representing the base URL and then use a URL constructor which builds a URL object from the URL representing the base URL and a string representing the relative URL: URL baseurl = new URL( ); URL url = new URL(baseURL, /papers.php ); Can also create a URL object from the URL s components: URL url = new URL( http, 80, /papers.php ); is the same as URL url = new URL( :80/papers.php );
13 Special characters and malformed URLs The string given to the URL constructor must not contain special characters Have to escape or encode the special characters before passing the string to the URL constructor e.g. World becomes Easiest way to do this is to create a java.net.uri object and then create a URL from this URI: URI uri = new URI( World ); URL url = uri.tourl(); A java.net.uri object represents a URI (Uniform Resource Identifier) A URI identifies a resource that may not actually exist anywhere on the network For example, XML namespaces are identified by URIs that do not necessarily point at actual web pages If a URL string given to a URL constructor is ill-formed, then the constructor throws a MalformedURLException Surround your URL constructor with a try-catch block! URLs are write-once objects you cannot change one once it has been constructed
14 Reading directly from a URL URL yahoo = new URL(" Uses following line to open a BufferedReader on the URL object stored in the variable, yahoo: BufferedReader in = new BufferedReader(new InputStreamReader(yahoo.openStream())); URL.openStream() returns an InputStream for reading from the URL InputStream is a stream of bytes to be read from An InputStreamReader takes the bytes from an InputStream and converts them into characters For improved efficiency, it is usually better to wrap an InputStreamReader in a BufferedReader A BufferedReader causes lines or chunks of characters to be read from a character input stream Without a BufferedReader, each read operation would involve reading a couple of bytes and converting into a character which is less efficient than is possible by reading chunks of bytes into a buffer and batch processing them The BufferedReader allows you to read the input one line at a time
15 Example //web page import java.net.*; import java.io.*; public class Pobierz { public static void main(string args[]) { URL url; String tekst; try { url = new URL(" InputStreamReader in = new InputStreamReader(url.openStream()); BufferedReader br = new BufferedReader(in); while( (tekst=br.readline())!=null) { System.out.println(tekst); catch (Exception e) {e.printstacktrace();
16 Connecting to a URL try { URL yahoo = new URL(" URLConnection yahooconnection = yahoo.openconnection(); yahooconnection.connect(); catch (MalformedURLException e) { // new URL() failed... catch (IOException e) { // openconnection() failed... Call a URL s openconnection() method to obtain a URLConnection object Subtype of URLConnection constructed depends on protocol of URL e.g., if http protocol, then HttpURLConnection constructed Connection between program and URL is only initiated when URLConnection.connect() method is called If call URLConnection s getinputstream() or getoutputstream() methods, then connection is initiated even if connect() method hasn t been called Once connection is initiated can read from and write to it
17 Sockets URLs and URLConnections are a high-level mechanism for accessing resources on the internet Sometimes you need to have lower-level communication between two programs that need to exchange information Client and server programs can establish a TCP connection with eachother Each program binds a socket to its own end of the connection Each program then reads from and writes to its socket
18 What is a socket? Server program runs on a particular machine and has a socket bound to a specific port number Server waits and listens to socket for a client to make a connection request Client is bound usually automatically to a port on the machine on which it is running Client tries to establish a connection with the server program on the latter s machine and port Server accepts connection request, gets a new socket bound to the same local port with its endpoint set to the address and port of the client Server continues to listen on its original socket Client and server can now communicate with each other by writing to and reading from their sockets
19 Socket and ServerSocket classes A socket is an endpoint of a TCP connection, identified by its IP address and port number A TCP connection can be uniquely identified by its endpoints java.net.socket represents one endpoint of a twoway connection between a Java program and some other program java.net.serversocket represents a socket that a server program can use to listen for incoming connection requests from clients
20 TCP ServerSocket ServerSocket(int port)* ServerSocket(int port, int backlog)* void close()* Socket accept()* InetAddress getinetaddress() int getlocalport() int getsotimeout()* void setsotimeout( int timeout)* String tostring() * Exceptions Socket Socket( InetAddress addr, int port)* Socket( InetAddress addr, int port, InetAddress localaddr, int localport)* void close()* InputStream getinputstream()* OutputStream getoutputsteam()* InetAddress getlocaladdress() InetAddress getinetaddress() int getlocalport() int getport() int getreceivebuffersize()* int getsendbuffersize()* void setreceivebuffersize(int size)* void setsendbuffersize(int size)* Int getsotimeout()* void setsotimeout(int timeout)*
21 TCP Socket, exceptions: try { Socket gniazdo = new Socket(" 80); catch (UnknownHostException e) {System.err.println(e); catch (IOException e) {{System.err.println(e); Streams: socket.getinputstream() socket.getoutputstream() Recomended for input: PrintWriter Recomended for output : BufferedReader Server, ServerSocket ServerSocket serwer = new ServerSocket(7) Socket socket= serwer.accept(), gniazdo.close()
22 Example port scanner import java.net.*; import java.io.*; public class SkanerPortow { public static void main(string[] args) { Socket gniazdo; String host = "localhost"; if (args.length > 0) { host = args[0]; //if not given // localhost for (int n = 0; n < 1024; n++) { try { gniazdo = new Socket(host, n); System.out.println( Open port"+n+ " on: "+ host); catch (UnknownHostException e) {System.err.println(e);break; catch (IOException e) {
23 Client server communication (chat - server) Users: multihreads loop (accept) and new thread for each connection import java.net.*; import java.io.*; public class ChatServer { public static void main(string args[]) throws IOException { if (args.length!= 1) throw new IllegalArgumentException( Usage: ChatServer <port>"); int port = Integer.parseInt(args[0]); ServerSocket server = new ServerSocket(port); while (true) { Socket client = server.accept(); new ChatHandler(client).start();
24 Client server communication (chat - server) import java.io.*; import java.net.*; import java.util.*; public class ChatHandler implements Runnable { protected static Vector handlers = new Vector(); protected Socket socket; protected DataInputStream datain; protected DataOutputStream dataout; protected Thread listener; public ChatHandler(Socket socket) { this.socket = socket;
25 Client server communication (chat - server) public synchronized void start() { if (listener == null) { try { datain = new DataInputStream( new BufferedInputStream( socket.getinputstream())); dataout = new DataOutputStream( new BufferedOutputStream( socket.getoutputstream())); listener = new Thread(this); listener.start(); catch (IOException ignored) { public synchronized void stop() { if (listener!= null) { try { if (listener!= Thread.currentThread()) listener.interrupt(); listener = null; dataout.close(); catch (IOException ignored) {
26 Client server communication (chat - server) public void run() { try { // list of users handlers.addelement(this); while (!Thread.interrupted()) { String message = datain.readutf(); broadcast(message); catch (EOFException ignored) { catch (IOException ex) { if (listener == Thread.currentThread()) ex.printstacktrace(); finally { // remove handlers.removeelement(this); stop();
27 Client server communication (chat - server) protected void broadcast(string message) { synchronized (handlers) { Enumeration enum = handlers.elements(); while (enum.hasmoreelements()) { ChatHandler handler = (ChatHandler) enum.nextelement(); try { handler.dataout.writeutf(message); handler.dataout.flush(); catch (IOException ex) { // cos się stalo handler.stop();
28 chat - client public class ChatClient extends JFrame implements Runnable, WindowListener, ActionListener { protected String host; protected int port; protected String username; protected JTextArea output; protected JTextField input; protected DataInputStream datain; protected DataOutputStream dataout; protected Thread listener; public ChatClient(String host, int port, String username) { super("chatclient [" + host + ':' + port + "]" + " (" + username + ")"); this.host = host; this.port = port; this.username = username;
29 chat - client public synchronized void start() throws IOException { if (listener == null) { Socket socket = new Socket(host, port); try { datain = new DataInputStream( new BufferedInputStream( socket.getinputstream())); dataout = new DataOutputStream( new BufferedOutputStream( socket.getoutputstream())); catch (IOException ex) { socket.close(); throw ex; listener = new Thread(this); listener.start(); makechatui();
30 chat - client public synchronized void stop() throws IOException { hide(); if (listener!= null) { listener.interrupt(); listener = null; dataout.close(); public void run() { try { while (!Thread.interrupted()) { String line = datain.readutf(); output.append(line + "\n"); catch (IOException ex) { handleioexception(ex);
31 chat - client protected void makechatui() { input = new JTextField(30); input.addactionlistener(this); output = new JTextArea(8,30); output.seteditable(false); Container c = getcontentpane(); c.add(new JScrollPane(output), BorderLayout.CENTER); c.add(input, BorderLayout.SOUTH); addwindowlistener(this); pack();show(); protected synchronized void handleioexception(ioexception ex) { if (listener!= null) { output.append(ex + "\n"); input.setvisible(false); validate(); if (listener!= Thread.currentThread()) listener.interrupt(); listener = null; try { dataout.close(); catch (IOException e) { e.printstacktrace();
32 chat - client public void windowopened(windowevent event) { input.requestfocus(); public void windowclosing(windowevent event) { try { stop(); catch (IOException ex) { ex.printstacktrace(); public void windowclosed(windowevent event) { public void windowiconified(windowevent event) { public void windowdeiconified(windowevent event) { public void windowactivated(windowevent event) { public void windowdeactivated(windowevent event) {
33 chat - client public void actionperformed(actionevent event) { try { input.selectall(); dataout.writeutf(username+": "+event.getactioncommand()); dataout.flush(); catch (IOException ex) {handleioexception(ex); public static void main(string[] args) throws IOException { if ((args.length!= 2) (args[0].indexof(':') < 0)) throw new IllegalArgumentException( "Uzycie: ChatKlient <host>:<port> <username>"); int idx = args[0].indexof(':'); String host = args[0].substring(0, idx); String username = args[1]; int port = Integer.parseInt(args[0].substring(idx + 1)); ChatKlient client = new ChatKlient(host, port, username); client.start();
34 Datagrams Some applications don t need the reliability of TCP Might benefit from using independent packages of information called datagrams whose arrival, content and order of arrival are not guaranteed UDP (User Datagram Protocol) provides protocol for sending datagrams UDP does not use connections as TCP does UDP in Java is done by sending and receiving DatagramPackets through DatagramSockets or MulticastSockets
35 (UDP) DatagramSocket DatagramSocket()* DatagramSocket(int port)* void close()* void connect(inetaddress a,int port) void disconnect() InetAddress getinetaddress() InetAddress getlocaladdress() int getlocalport() int getport() void receive(datagrampacket p)* void send(datagrampacket p)* DatagramPacket DatagramPacket(byte[] buf,int length) DatagramPacket(byte[] buf,int length, InetAddress addr, int port) byte[] getdata() int getlength() int getport() InetAddress getaddress() void setaddress(inetaddress addr) void setdata(byte[] data) void setlength(int length void setport(int port)
36 Client-server (UDP) Client side DatagramSocket socket = new DatagramSocket(); Server side DatagramSocket = new DatagramSocket(PORT_NUM); Client->Server byte[] buf = new byte[256]; InetAddress address = InetAddress.getByName("server-name"); DatagramPacket sendpacket = new DatagramPacket(buf, buf.length, address, PORT_NUM); socket.send( sendpacket ); Receiving byte[] buf = new byte[256]; DatagramPacket receivepacket = new DatagramPacket(buf, buf.length); socket.receive(receivepacket); Reply InetAddress address = receivepacket.getaddress(); int port = receivepacket.getport(); DatagramPacket respondpacket = new DatagramPacket(buf, buf.length, address, port); socket.send( respondpacket );
37 Broadcasting to Multiple Recipients java.net.multicastsocket used on client-side to listen for packets broadcast by server to multiple clients MulticastSocket extends DatagramSocket MulticastSocket()* MulticastSocket(int port)* void joingroup(inetaddress group)* void leavegroup(inetaddress group)* InetAddress getinetaddress()* void send(datagrampacket p, byte ttl)* void settimetolive( int ttl )* Int gettimetolive()*
38 MulticastServer Port number doesn t matter as client never sends anything to server InetAddress group = InetAddress.getByName(" "); DatagramPacket packet; packet = new DatagramPacket(buf, buf.length, group, 4446); Server doesn t have to get IP address and port number from client now, as it is broadcasting to all clients in group with IP address , listening on port 4446
39 MulticastClient Constructs a MulticastSocket and binds to port number 4446, which is the one that MulticastServer is transmitting to Uses the MulticastSocket.joinGroup(InetAddress) method to join the group through are available as multicast addresses (D) Uses the MulticastSocket.receive(packet) method to receive the next packet transmitted by the server When finished, leaves the group using socket.leavegroup(address) Then closes socket
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 informationPrevious 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 informationNetworking 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 informationJAVA - 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 informationNetworking 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 informationSocket 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 informationLecture 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 informationNetwork Programming. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff
Network Programming by Vlad Costel Ungureanu for Learn Stuff Java Network Protocols 2 Java Network Protocols 3 Addresses Innet4Address (32-bit) 85.122.23.145 - numeric pentalog.com symbolic Innet6Address
More informationCSCD 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 informationInterprocess 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 informationCSCD 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 informationJava 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 informationJava.net Package and Classes(Url, UrlConnection, HttpUrlConnection)
Java.net Package and Classes(Url, UrlConnection, HttpUrlConnection) Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in
More informationPrinciples, 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 informationCSCD 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 informationNetworking: 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 informationNetworking 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 informationBasic 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 informationIntroduction 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 informationLecture 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 informationInfo 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 informationDistributed Programming in Java
Distributed Programming in Java Networking (1) Motivating Scenario apps apps apps apps 2/28 apps nslookup A program for looking up IP addresses 3/28 1 InetAddress This class represents an IP address Each
More informationNetworks 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 informationAssignment 1. Due date February 6, 2007 at 11pm. It must be submitted using submit command.
Assignment 1 Due date February 6, 2007 at 11pm. It must be submitted using submit command. Note: submit 4213 a1 . Read the manpages ("man submit") for more details on the submit command. It is
More informationJAVA 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 informationInfo 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub
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 Starting Network
More informationUnit 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 informationEx. No. : 1 Retrieving Data using URL Procedure URLs A URL identifies the location of a resource on the Internet. It specifies the protocol used to access a server (e.g., FTP, HTTP), the name of the server,
More informationOutlines. 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 informationSERVER/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 informationNetwork 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 informationJAVA 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 informationCOMP 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 informationDistributed 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 informationCPSC 441 UDP Socket Programming. Department of Computer Science University of Calgary
CPSC 441 UDP Socket Programming Department of Computer Science University of Calgary Socket programming using UDP (vs TCP) UDP: no connection between client and server vno handshaking vsender explicitly
More informationOutline of Topics. UDP Socket Java Programming. Multicast in Java. Real-time protocol (RTP) XMPP and Jingle protocols. Java I/O and New IO (NIO)
Outline Outline of Topics UDP Socket Java Programming Multicast in Java Real-time protocol (RTP) XMPP and Jingle protocols Java I/O and New IO (NIO) UDP Socket Java Programming User Datagram Protocol (UDP)
More informationNetwork. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark
Network Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark jbb@ase.au.dk Outline Socket programming If we have the time: Remote method invocation (RMI) 2 Socket Programming Sockets
More informationTransport 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 informationJava 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 informationPieter 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 informationCommunication 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 informationDistributed 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 informationPrinciples 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 informationChapter 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 informationJava Technologies. Lecture VII. Valdas Rapševičius. Vilnius University Faculty of Mathematics and Informatics
Preparation of the material was supported by the project Increasing Internationality in Study Programs of the Department of Computer Science II, project number VP1 2.2 ŠMM-07-K-02-070, funded by The European
More informationDistributed 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 informationAJP: 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 informationInternet 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 informationCommunication 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 informationCS 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 informationprotocols 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 informationC19: User Datagram and Multicast
CISC 3120 C19: User Datagram and Multicast Hui Chen Department of Computer & Information Science CUNY Brooklyn College 4/18/2018 CUNY Brooklyn College 1 Outline Recap Network fundamentals IPv4, IPv6 addresses
More information31 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 informationWeek 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 informationNetworking in Java. Java Fundamentals. Dmitri Gabbasov Tartu 2016
Networking in Java Java Fundamentals Dmitri Gabbasov Tartu 2016 The java.net package java.net.socket represents a TCP connection to a remote endpoint java.net.serversocket represents a TCP endpoint that
More informationConstruction d Applications Réparties / Master MIAGE
Construction d Applications Réparties / Master MIAGE Networking Giuseppe Lipari CRiSTAL, Université de Lille January 26, 2016 Outline Introduction Networking Transport Protocols TCP and UDP Addressing
More informationTCP Networking in Java. Some reminders
TCP Networking in Java Some reminders Protocol Synonymous of Etiquette a code of behavior that delineates expectations for social behavior according to contemporary conventional norms within a society,
More informationIntroduction 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 informationCPSC 441 Assignment-3 Discussion. Department of Computer Science University of Calgary
CPSC 441 Assignment-3 Discussion Department of Computer Science University of Calgary Overview of FastFTP protocol TCP for Initial Handshake Port: 2245 Port: 4576 You may choose any free port >1024 at
More informationTCP 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 informationDistributed 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 informationChapter 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 informationCPSC 441 Tutorial - 11 UDP Socket Programming Department of Computer Science University of Calgary
CPSC 441 Tutorial - 11 UDP Programming Department of Computer Science University of Calgary TCP Vs UDP Input: receives packet (TCP receives byte stream ) Output: sends packet (TCP sends byte stream ) What
More informationJava Basics 5 - Sockets. Manuel Oriol - May 4th, 2006
Java Basics 5 - Sockets Manuel Oriol - May 4th, 2006 Connected / Disconnected Modes Connected mode: path chosen and packets arrive all, in correct order (e.g. Phone) Disconnected mode: path not chosen
More informationCS 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 informationJoseph Faber Wonderful Talking Machine (1845)
Joseph Faber Wonderful Talking Machine (1845) Connected World Human-to-Human communication Human-Machine interaction Machine-to-Machine communication (M2M) Internet-of-Things (IOT) Internet of Things How
More informationWeb 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 informationConnecting 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 informationChapter 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 informationObject-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 informationURL Kullanımı Get URL
Networking 1 URL Kullanımı Get URL URL info 2 import java.io.*; import java.net.*; public class GetURL { public static void main(string[] args) { InputStream in = null; OutputStream out = null; // Check
More informationJava for Interfaces and Networks
Java for Interfaces and Networks Threads and Networking Federico Pecora School of Science and Technology Örebro University federico.pecora@oru.se Federico Pecora Java for Interfaces and Networks Lecture
More informationSocket Programming in Java
Socket Programming in Java Objectives: Learn about the basic java classes (java.net package) that supports Socket programming, namely: o InetAddress o Socket o ServerSocket o DatagramSocket o DatagramPacket
More informationChapter 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 informationMulti-threaded Web Server (Assignment 1) Georgios Georgiadis
Multi-threaded Web Server (Assignment 1) Georgios Georgiadis Overview Multi-threaded Web Server What to do and how to do it HTTP messages Processes and threads ComputerComm '09 2 Multi-threaded Web Server
More informationC18: Network Fundamentals and Reliable Sockets
CISC 3120 C18: Network Fundamentals and Reliable Sockets Hui Chen Department of Computer & Information Science CUNY Brooklyn College 4/16/2018 CUNY Brooklyn College 1 Outline Networking fundamentals Network
More informationPrinciples, Models, and Applications for Distributed Systems M
Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M Exercitation 3 Connected Java Sockets Jacopo De Benedetto Distributed architecture
More informationJava for Interfaces and Networks (DT3029)
Java for Interfaces and Networks (DT3029) Lecture 3 Threads and Networking Federico Pecora federico.pecora@oru.se Center for Applied Autonomous Sensor Systems (AASS) Örebro University, Sweden Capiscum
More informationJava Socket Workshop. July Purpose of this workshop:
Java Socket Workshop July 2012 Purpose of this workshop: The objective of this workshop is to gain experience with writing and compiling programs using the Java programming language. The exercises provide
More informationReliability is an issue. You cannot afford to have any of the data lost or re-ordered.
Appendix C Socket Programming C.1 Socket Programming in Java C.1.1 Networking Basics Computers running on the Internet communicate to each other using the Internet Protocol (IP). Usually the Transmission
More informationSocket 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 informationChapter 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 informationPrinciples, 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 4 (worked-out) Connection-oriented Java Sockets Luca Foschini Winter
More informationReading from URL. Intent - open URL get an input stream on the connection, and read from the input stream.
Simple Networking Loading applets from the network. Applets are referenced in a HTML file. Java programs can use URLs to connect to and retrieve information over the network. Uniform Resource Locator (URL)
More informationJava 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 informationCPSC 441 Assignment-3 Discussion. Department of Computer Science University of Calgary
CPSC 441 Assignment-3 Discussion Department of Computer Science University of Calgary Overview of FastFTP protocol TCP for Initial Handshake Port: 1111 Port: 4444 UDP for File Content Transfer Port: 3333
More informationJava Programming Language Advance Feature
Java Programming Language Advance Feature Peter.Cheng founder_chen@yahoo.com.cn http://www.huihoo.com 2004-04 Huihoo - Enterprise Open Source http://www.huihoo.com 1 Course Goal The main goal of this course
More informationIntroduction 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 informationOBJECT 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 informationChapter 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 informationInternet 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 informationWorld 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 informationIntroduction 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 informationLab 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 informationChapter 12. Network Programming
Chapter 12 Network Programming What is in This Chapter? This chapter explains how to connect your JAVA application to a network. You will learn how to read files from over the internet as well as have
More informationNetworking Code CSCI 201 Principles of Software Development
Networking Code CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. jeffrey.miller@usc.edu Server Networking Client Networking Program Outline USC CSCI 201L Server Software A server application
More informationRedesde Computadores(RCOMP)
Redesde Computadores(RCOMP) Theoretical-Practical (TP) Lesson 06 2016/2017 Berkeley sockets API, C and Java. Address families and address storing. Basic functions/methods for UDP applications. UDP client
More informationInterprocess Communication
Interprocess Communication Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved. 0-13-239227-5 Introduction Applications, services
More informationLayer 4 - Transport Layer. What do we need a Transport Layer for? Transport Protocols in the TCP/IP Reference Model. The Transport Layer TCP and UDP
Layer 4 - Transport Layer Core of the protocol hierarchy: Network-independent, reliable and economical data transfer Tasks of the transport layer: Connection-oriented or connectionless data transfer Addressing
More informationSoftware Practice 1 - Socket
Software Practice 1 - Socket Terms of socket programming Socket Implementation (TCP, UDP) Socket with multithread Serialization Lab practice Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim T.A. Sujin
More information