Network Programming. Java provides easy-to-use classes for network programming. These classes integrate nicely with the rest of the language.
|
|
|
- Erick Payne
- 9 years ago
- Views:
Transcription
1 Network Programming Java provides easy-to-use classes for network programming. These classes integrate nicely with the rest of the language. Acronyms IP TCP UDP URL HTTP FTP SMTP POP Connections = Internet Protocol = Transport Control Protocol = User Datagram Protocol = Uniform Resource Locator = Hypertext Transfer Protocol = File Transfer Protocol = Simple Mail Transfer Protocol = Post Office Protocol A connection with a computer on the Internet is described by 1. A host or domain name (blue.weeg.uiowa.edu) or An IP address, a 32-bit integer written as four bytes ( ), called dotted quad format. 2. A port number, a 16-bit integer (1 port 65535). The Domain Naming Service (DNS) translates host names into IP addresses. DNS consists of a set of servers on the Internet that translate host names. Copyright 2005 by Ken Slonneger Network Programming 1
2 Ports The ports from 1 to 1023 are reserved for well-known network services, for example, 7 echo 9 discard 13 daytime 21 ftp 25 smtp 37 time 43 whois 79 finger 80 http 110 pop3 Networking in Java Java provides classes for programming network applications at a relatively high level. We consider two groups of classes: 1. IP address class 2. TCP classes InetAddress Class Each object of class InetAddress encapsulates one IP address. InetAddress has no public constructors. Objects are created using class methods, called factory methods. InetAddress InetAddress.getByName(String hostname) throws UnknownHostException Also InetAddress [] InetAddress.getAllByName(String hostname) InetAddress InetAddress.getLocalHost() 2 Network Programming Copyright 2005 by Ken Slonneger
3 Example (in a try block) InetAddress cs = InetAddress.getByName("john.cs.uiowa.edu"); Accessors Instance methods: cs.gethostname() cs.getaddress() returns a String returns a byte array Example: Find IP Addresses List the IP addresses for cnn.com or some other host. Recall that the bytes between 128 and 255 are negative integers as twos complement numbers. import java.net.*; public class Inet public static void main(string [] args) throws UnknownHostException InetAddress [] ia; if (args.length == 1) ia = InetAddress.getAllByName(args[0]); else ia = InetAddress.getAllByName("cnn.com"); for (int k = 0; k < ia.length; k++) System.out.println(ia[k]); System.out.println(ia[k].getHostName()); byte [] bytes = ia[k].getaddress(); Copyright 2005 by Ken Slonneger Network Programming 3
4 for (int n=0; n<bytes.length; n++) int b = bytes[n]; if (b<0) b = b+256; if (n>0) System.out.print(. ); System.out.print(b); System.out.println(); Negative bytes need to be massaged to put them into the range 0 to 255. Example: Start with the byte -52 byte int which is the unsigned byte 204 as an int. Note that the sign is extended when a byte is changed into an int. Output cnn.com/ cnn.com cnn.com/ cnn.com cnn.com/ cnn.com cnn.com/ cnn.com cnn.com/ cnn.com cnn.com/ cnn.com cnn.com/ cnn.com cnn.com/ cnn.com Network Programming Copyright 2005 by Ken Slonneger
5 TCP/IP: Connection-Oriented Protocol Similar to a telephone conversation. Server Listens at a particular port for incoming conversations. Client Initiates a conversation with a server by naming the server and the port at which the server is listening. Client Application Socket Server Socket Client Application Socket Server Socket Socket Copyright 2005 by Ken Slonneger Network Programming 5
6 Sockets A socket is an abstraction that treats a network connection as a stream of bytes that can be read or written. A socket is constructed by a client explicitly when it connects with a server. Socket Class Constructors Socket sock = new Socket("rome.divms.uiowa.edu", 7); If we already have an InetAddress, say inad, use Socket sk = new Socket(inad, 7); Accessors sock.getinetaddress() sock.getport() sock.getlocalport() returns remote host returns remote port returns local port Creating Streams InputStream is = sock.getinputstream(); OutputStream os = sock.getoutputstream(); Closing a Socket sock.close(); 6 Network Programming Copyright 2005 by Ken Slonneger
7 Example: Echo Client Connect to the echo port on a unix machine. import java.net.*; import java.io.*; public class EchoClient public static void main(string [] args) String hostname; if (args.length > 0) hostname = args[0]; else hostname = "localhost"; try Socket sock = new Socket(hostname, 7); System.out.println("Connected to " + sock.getinetaddress()); BufferedReader instream = new BufferedReader( new InputStreamReader(sock.getInputStream())); boolean autoflush = true; PrintWriter outstream = new PrintWriter( new OutputStreamWriter( sock.getoutputstream()), autoflush); BufferedReader userinput = new BufferedReader( new InputStreamReader(System.in)); Copyright 2005 by Ken Slonneger Network Programming 7
8 System.out.println("Enter text with. at end"); String aline = userinput.readline(); while (!aline.equals(".")) System.out.println("User: " + aline); outstream.println(aline); System.out.println("Echo: " + instream.readline()); aline = userinput.readline(); sock.close(); catch (UnknownHostException e) System.out.println(e); catch (IOException e) System.out.println(e); % java EchoClient cse.buffalo.edu Connected to cse.buffalo.edu/ Enter text with. to end Hello buffalo. User: Hello buffalo. Echo: Hello buffalo. How is Lake Erie? User: How is Lake Erie? Echo: How is Lake Erie? This will be the last line. User: This will be the last line. Echo: This will be the last line.. 8 Network Programming Copyright 2005 by Ken Slonneger
9 Example: Look for Ports Connect to a host and try all the ports from 1 to 1023 to see if they accept a connection. Use a command-line argument. Try on friendly machines only. import java.net.*; import java.io.*; public class Look4Ports public static void main(string [] args) String host; Socket thesocket = null; if (args.length>0) host = args[0]; else host = "localhost"; try for (int k=1; k<1024; k++) try thesocket = new Socket(host, k); System.out.println("Port " + k + " of " + host + " has a server."); catch (ConnectException e) /* no server on this port: throws a ConnectException */ Copyright 2005 by Ken Slonneger Network Programming 9
10 if (thesocket!=null) thesocket.close(); catch (UnknownHostException e) System.out.println(e); catch (IOException e) System.out.println(e); % java Look4Ports red.weeg.uiowa.edu Port 21 of red.weeg.uiowa.edu has a server. Port 22 of red.weeg.uiowa.edu has a server. Port 23 of red.weeg.uiowa.edu has a server. Port 25 of red.weeg.uiowa.edu has a server. Port 106 of red.weeg.uiowa.edu has a server. Port 110 of red.weeg.uiowa.edu has a server. Port 111 of red.weeg.uiowa.edu has a server. Port 113 of red.weeg.uiowa.edu has a server. Port 512 of red.weeg.uiowa.edu has a server. Port 513 of red.weeg.uiowa.edu has a server. Port 514 of red.weeg.uiowa.edu has a server. Port 620 of red.weeg.uiowa.edu has a server. Port 621 of red.weeg.uiowa.edu has a server. Port 999 of red.weeg.uiowa.edu has a server. 10 Network Programming Copyright 2005 by Ken Slonneger
11 Server Sockets Constructor ServerSocket ss = new ServerSocket(2233); Parameter is an int specifying the port. The port number must be greater than Instance Method Socket sock = ss.accept(); Blocks until a client requests session with this host on server port. Returns a Socket when a connection is made. Example: Echo Server Create a server that echoes each string that is sent to it, terminating when BYE is the string. import java.io.*; import java.net.*; public class EchoServer public static void main(string [] args) try ServerSocket ss = new ServerSocket(7007); System.out.println("Echo Server running on " + InetAddress.getLocalHost().getHostName()); Copyright 2005 by Ken Slonneger Network Programming 11
12 Socket incoming = ss.accept( ); String client = incoming.getinetaddress().gethostname(); System.out.println("Connection made with " + client); BufferedReader br = new BufferedReader( new InputStreamReader(incoming.getInputStream())); PrintWriter pw = new PrintWriter( new OutputStreamWriter( incoming.getoutputstream()), true); pw.println("hello! Enter BYE to exit.\n"); String str = br.readline(); while (str!= null &&!str.trim().equals("bye")) pw.println("echo: " + str + "\n"); str = br.readline(); incoming.close(); catch (IOException e) System.out.println(e); 12 Network Programming Copyright 2005 by Ken Slonneger
13 The EchoServer can be tested using telnet. A telnet session is initiated by a unix command: % telnet remotemachinename portnumber First Start EchoServer on a machine (l-lnx205). % java EchoServer Echo Server running on l-lnx205.divms.uiowa.edu Connection made with r-lnx233.cs.uiowa.edu Second: Start telnet on r-lnx233.cs.uiowa.edu % telnet l-lnx205.divms.uiowa.edu 7007 Trying... Connected to l-lnx205.divms.uiowa.edu. Escape character is '^]'. Hello! Enter BYE to exit. Hello l-lnx205. Echo: Hello l-lnx205. This session comes from telnet. Echo: This session comes from telnet. BYE Connection closed by foreign host. These lines produced by telnet. Copyright 2005 by Ken Slonneger Network Programming 13
14 Anonymous Mail Using the simple mail transfer protocol, SMTP, we can send mail anonymously. First, make a connection at port 25 with the server that contains the addressee to whom you want to send the mail and then send the following linefeed-terminated strings: Client Messages <connect> HELO sun.com MAIL FROM: [email protected] RCPT TO: slonnegr DATA Hello from nobody.. Responses from Server 220 smtp.divms.uiowa.edu ESMTP Tue, 9 Nov :49: (CST) 250 serv01.divms.uiowa.edu Hello [ ], pleased to meet you 250 [email protected]... Sender ok 250 slonnegr...recipient ok 354 Enter mail, end with "." on a line by itself 250 PAA24437 Message accepted for delivery 14 Network Programming Copyright 2005 by Ken Slonneger
15 POP3 Protocol % telnet mail.divms.uiowa.edu 110 Trying... Connected to mail.divms.uiowa.edu. Escape character is '^]'. +OK POP3 mail.divms.uiowa.edu v server ready USER slonnegr +OK User name accepted, password please PASS ********* +OK Mailbox open, 249 messages RETR 20 +OK 2659 octets : From: "stephenmosberg" <[email protected]> To: "Ken Slonneger" <[email protected]> Subject: Thank You Date: Mon, 6 May :44: : Dear Professor Slonneger: I wanted to thank you for your helpful review of the proposal. :. QUIT +OK Sayonara Connection closed by foreign host. Copyright 2005 by Ken Slonneger Network Programming 15
16 Protocols and Serialization For programs on two different machines to communicate, each needs to know what the other is expecting. For example, is possible because of the Simple Mail Transfer Protocol (smtp). Suppose we want to provide a new service that clients can use, namely the generation of Domino objects. First we need to define the protocol, call it the Domino Transfer Protocol (dtp). DominoClient DominoServer connect > < Enter number of dominoes desired an int n > < n randomly generated dominoes < terminate connection > Since Domino objects need to be serialized to be sent across the network, all data will be sent through object streams. When object streams are created between two programs, header information including magic numbers are exchanged and verified. Therefore, the object streams must be created in compatible orders. 16 Network Programming Copyright 2005 by Ken Slonneger
17 Server ObjectOutputStream sock.getoutputstream() ObjectInputStream sock.getinputstream() Client ObjectInputStream sock.getinputstream() ObjectOutputStream sock.getoutputstream() Domino Server import java.io.*; import java.net.*; public class DominoServer public static void main(string[] args) try ServerSocket ss = new ServerSocket(9876); System.out.println("Domino Server running."); System.out.println("Use cntl-c to stop server."); while (true) Socket sock = ss.accept( ); String client = sock.getinetaddress().gethostname(); System.out.println("Connected to client " + client); Copyright 2005 by Ken Slonneger Network Programming 17
18 InputStream in = sock.getinputstream(); OutputStream out = sock.getoutputstream(); // Note order of Object stream creation. ObjectOutputStream outstrm = new ObjectOutputStream(out); ObjectInputStream instrm = new ObjectInputStream(in); outstrm.writeutf("enter number of dominoes desired"); outstrm.flush(); int count = instrm.readint(); for (int k=1; k<=count; k++) Domino d = new Domino(true); outstrm.writeobject(d); System.out.println(count + " dominoes sent to " + client); sock.close(); // flushes the stream // while (true) catch (IOException e) System.out.println(e); /****************************************************/ class Domino implements Serializable : 18 Network Programming Copyright 2005 by Ken Slonneger
19 Domino Client import java.net.*; import java.io.*; public class DominoClient public static void main(string[] args) String hostname; int port = 9876; if (args.length == 1) hostname = args[0]; else System.out.println( "Usage: java DominoClient servername"); return; try Socket sock = new Socket(hostname, port); String server = sock.getinetaddress().gethostname(); System.out.println("Connected to server " + server); InputStream in = sock.getinputstream(); OutputStream out = sock.getoutputstream(); // Note order of Object stream creation. ObjectInputStream instrm = new ObjectInputStream(in); ObjectOutputStream outstrm = new ObjectOutputStream(out); Scanner scan = new Scanner(System.in); Copyright 2005 by Ken Slonneger Network Programming 19
20 String start = instrm.readutf(); System.out.print(start + ": "); String aline = userinput.readline(); int num; try num = scan.nextint(); catch (InputMismatchException e) num = 0; outstrm.writeint(num); outstrm.flush(); for (int k=1; k<=num; k++) Domino d = (Domino)inStrm.readObject(); System.out.println("Domino " + k +": " + d); sock.close(); catch (UnknownHostException e) System.out.println(e); catch (ClassNotFoundException e) System.out.println(e); catch (IOException e) System.out.println(e); /****************************************************/ class Domino implements Serializable : 20 Network Programming Copyright 2005 by Ken Slonneger
21 Sample Server Output % java DominoServer Domino Server running on l-lnx205.divms.uiowa.edu Use control-c to terminate server. Connection from client: r-lnx233.cs.uiowa.edu 5 dominoes sent to r-lnx233.cs.uiowa.edu Sample Client Output % java DominoClient l-lnx205.divms.uiowa.edu Connected to server l-lnx205.divms.uiowa.edu Enter the number of dominoes desired: 5 Domino 1: <1, 1> UP Domino 2: <2, 3> UP Domino 3: <0, 0> UP Domino 4: <1, 4> UP Domino 5: <1, 1> UP Another Protocol Most network protocols are text-based. The client and server exchange text messages (strings). Examples: echo, date, smtp, pop3, http A Non-text Protocol: time Some machines have a server running on port 37 that returns binary data. When a client connects to such a server at port 37, the server returns a four-byte (32-bit) unsigned integer representing the number of seconds since midnight on January 1, 1900 GMT. Copyright 2005 by Ken Slonneger Network Programming 21
22 Since the number of seconds that have elapsed since January 1, 1900 GMT is already larger than the biggest positive int in Java (2,147,483,647), we must convert the four byte number to long to see the correct value. Client Program import java.net.*; import java.io.*; // TCP to port 37 public class Time37 public static void main(string [] args) throws IOException String host; if (args.length == 1) host = args[0]; else throw new RuntimeException( "Usage: java Time37 time.nist.gov"); Socket s = new Socket(host, 37); InputStream instream = s.getinputstream(); byte [] buffer = new byte [4]; int count = instream.read(buffer); long secs = 0; for (int k=0; k<4; k++) // use long arithmetic so that long b = buffer[k]; // after the shift left one byte, secs = secs << 8; // the number will be positive secs = secs (b & 0xff); // place byte in right-most // position 22 Network Programming Copyright 2005 by Ken Slonneger
23 System.out.println(secs + " seconds since January 1, 1900, GMT"); Sample Execution % java Time37 time.nist.gov seconds since January 1, 1900, GMT Exercise: Calculate the number of day, hours, minutes, and seconds that have elapsed since January 1, 1900 GMT. Exercise: Use a DataInputStream to read the four bytes as an int. If the number is negative (it will be), use long arithmetic to make if positive by adding HTTP The hypertext transport protocol defines the convention that allows a browser to find web pages on a server. The basic web page fetch follows a simple protocol. Protocol 1. Connect to the machine where the server in running, normally at port 80. 2a. Send a line of text that includes the name of the file to be returned. GET /index.html HTTP/1.0 In most web directories, the file index.html contains the starting web page for the directory. 2b. Or omit the file name. GET / HTTP/1.0 Copyright 2005 by Ken Slonneger Network Programming 23
24 3. Send a header specifying the host (for HTTP 1.1): Host: server we are connecting to 4. Enter one entirely blank line. At this point the web server should send back the web page as a stream of text, usually written in HTML. The program below acts as a client that connects to a web server given by its first command-line argument, and downloads a file given by its second command-line argument. If no command-line arguments are supplied, the program connects to yahoo.com and downloads index.html. The program uses a Scanner object to read the lines of text sent back by the web server. HttpClient.java import java.io.*; import java.net.*; import java.util.scanner; public class HttpClient public static void main(string [] args) throws IOException String server="yahoo.com", file="index.html"; if (args.length == 2) file = args[1]; if (args.length >= 1) server = args[0]; Socket sock = new Socket(server, 80); PrintWriter pw = new PrintWriter(sock.getOutputStream(),true); 24 Network Programming Copyright 2005 by Ken Slonneger
25 pw.println("get /" + file + " HTTP/1.0"); pw.println("host: " + server); // Required by HTTP 1.1 pw.println(); Scanner scan = new Scanner(sock.getInputStream()); while (scan.hasnextline()) String str = scan.nextline(); System.out.println(str); sock.close(); Execution % java HttpClient <!-- info_setup:ads,ad-location:z,ad-spaceid: > <!-- info_insertion:z > <!-- spaceid: > <html> <head><title>ask Yahoo!</title> <meta http-equiv="pics-label" content='(pics-1.1 " l gen true for " r ( nz 0 vz 0 lz 0 oz 0 ca 1))'> </head> <body bgcolor=white> <center> <table border=0 width=600 cellspacing=0 cellpadding=0> <tr> <td width=1%><img src= alt="ask Yahoo!" border=0 width=167 height=35></td> <td> <table border=0 cellspacing=0 cellpadding=0 width=100%> <tr> <td align=right valign=bottom><font face=arial size=-1> Copyright 2005 by Ken Slonneger Network Programming 25
26 <a href=" Site Directory</a> - : Using Telnet % telnet java.sun.com 80 Trying Connected to available ( ). Escape character is '^]'. GET / HTTP/1.0 HTTP/ OK Server: Sun-ONE-Web-Server/6.1 Date: Thu, 12 May :39:11 GMT Content-type: text/html;charset=iso Set-Cookie: SUN_ID= : ; EXPIRES=Wednesday, 31-Dec :59:59 GMT; DOMAIN=.sun.com; PATH=/ Set-cookie: JSESSIONID=514ED4E39D287F2DA E05C1359;Path=/ Connection: close <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>java Technology</title> <meta name="keywords" content="java, platform" /> <meta name="description" content="java technology is a portfolio of products that are based on the power of networks and the idea that the same software should run on many different kinds of systems and devices." /> : 26 Network Programming Copyright 2005 by Ken Slonneger
Division of Informatics, University of Edinburgh
CS1Bh Lecture Note 20 Client/server computing A modern computing environment consists of not just one computer, but several. When designing such an arrangement of computers it might at first seem that
Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP
CP4044 Lecture 7 1 Networking Learning Outcomes To understand basic network terminology To be able to communicate using Telnet To be aware of some common network services To be able to implement client
Application Development with TCP/IP. Brian S. Mitchell Drexel University
Application Development with TCP/IP Brian S. Mitchell Drexel University Agenda TCP/IP Application Development Environment Client/Server Computing with TCP/IP Sockets Port Numbers The TCP/IP Application
Lesson: All About Sockets
All About Sockets http://java.sun.com/docs/books/tutorial/networking/sockets/index.html Page 1 sur 1 The Java TM Tutorial Start of Tutorial > Start of Trail Trail: Custom Networking Lesson: All About Sockets
Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?
CSCI 312 - DATA COMMUNICATIONS AND NETWORKS FALL, 2014 Assignment 4 Working as a group. Working in small gruops of 2-4 students. When you work as a group, you have to return only one home assignment per
Network/Socket Programming in Java. Rajkumar Buyya
Network/Socket Programming in Java Rajkumar Buyya Elements of C-S Computing a client, a server, and network Client Request Result Network Server Client machine Server machine java.net Used to manage: URL
Network Communication
Network Communication Outline Sockets Datagrams TCP/IP Client-Server model OSI Model Sockets Endpoint for bidirectional communication between two machines. To connect with each other, each of the client
Socket Programming in Java
Socket Programming in Java Learning Objectives The InetAddress Class Using sockets TCP sockets Datagram Sockets Classes in java.net The core package java.net contains a number of classes that allow programmers
Java Network. Slides prepared by : Farzana Rahman
Java Network Programming 1 Important Java Packages java.net java.io java.rmi java.security java.lang TCP/IP networking I/O streams & utilities Remote Method Invocation Security policies Threading classes
Building a Multi-Threaded Web Server
Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous
Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1
Introduction to Java Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233 ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1 What Is a Socket? A socket is one end-point of a two-way
Assignment 4 Solutions
CSCI 312 - DATA COMMUNICATIONS AND NETWORKS FALL, 2014 Assignment 4 Solutions Working as a pair Working in pairs. When you work as a pair you have to return only one home assignment per pair on a round.
Mail User Agent Project
Mail User Agent Project Tom Kelliher, CS 325 100 points, due May 4, 2011 Introduction (From Kurose & Ross, 4th ed.) In this project you will implement a mail user agent (MUA) that sends mail to other users.
Remote login (Telnet):
SFWR 4C03: Computer Networks and Computer Security Feb 23-26 2004 Lecturer: Kartik Krishnan Lectures 19-21 Remote login (Telnet): Telnet permits a user to connect to an account on a remote machine. A client
File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)
File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The
The Application Layer. CS158a Chris Pollett May 9, 2007.
The Application Layer CS158a Chris Pollett May 9, 2007. Outline DNS E-mail More on HTTP The Domain Name System (DNS) To refer to a process on the internet we need to give an IP address and a port. These
Socket programming. Complement for the programming assignment INFO-0010
Socket programming Complement for the programming assignment INFO-0010 Outline Socket definition Briefing on the Socket API A simple example in Java Multi-threading and Synchronization HTTP protocol Debugging
Object-Oriented Programming in Java
CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio
1 Introduction: Network Applications
1 Introduction: Network Applications Some Network Apps E-mail Web Instant messaging Remote login P2P file sharing Multi-user network games Streaming stored video clips Internet telephone Real-time video
Creating a Simple, Multithreaded Chat System with Java
Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate
NETWORK PROGRAMMING IN JAVA USING SOCKETS
NETWORK PROGRAMMING IN JAVA USING SOCKETS Prerna Malik, Poonam Rawat Student, Dronacharya College of Engineering, Gurgaon, India Abstract- Network programming refers to writing programs that could be processed
The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)
Binary I/O streams (ascii, 8 bits) InputStream OutputStream The Java I/O System The decorator design pattern Character I/O streams (Unicode, 16 bits) Reader Writer Comparing Binary I/O to Character I/O
Agenda. Network Programming and Java Sockets. Introduction. Internet Applications Serving Local and Remote Users
Programming and Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering University of Melbourne, Australia http://www.cs.mu.oz.au/~raj
Network Technologies
Network Technologies Glenn Strong Department of Computer Science School of Computer Science and Statistics Trinity College, Dublin January 28, 2014 What Happens When Browser Contacts Server I Top view:
Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol).
Java Network Programming The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol). The DatagramSocket class uses UDP (connectionless protocol). The java.net.socket
Data Communication & Networks G22.2262-001
Data Communication & Networks G22.2262-001 Session 10 - Main Theme Java Sockets Dr. Jean-Claude Franchitti New York University Computer Science Department Courant Institute of Mathematical Sciences 1 Agenda
FTP client Selection and Programming
COMP 431 INTERNET SERVICES & PROTOCOLS Spring 2016 Programming Homework 3, February 4 Due: Tuesday, February 16, 8:30 AM File Transfer Protocol (FTP), Client and Server Step 3 In this assignment you will
Chapter 20 Streams and Binary Input/Output. Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved.
Chapter 20 Streams and Binary Input/Output Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved. 20.1 Readers, Writers, and Streams Two ways to store data: Text
String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket.
164 CHAPTER 2 APPLICATION LAYER connection requests, as done in TCPServer.java. If multiple clients access this application, they will all send their packets into this single door, serversocket. String
INPUT AND OUTPUT STREAMS
INPUT AND OUTPUT The Java Platform supports different kinds of information sources and information sinks. A program may get data from an information source which may be a file on disk, a network connection,
public static void main(string[] args) { System.out.println("hello, world"); } }
Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static
Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets
Transport layer protocols Interprocess communication Synchronous and asynchronous comm. Message destination Reliability Ordering Client Server Lecture 15: Operating Systems and Networks Behzad Bordbar
Introduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
CISC 4700 L01 Network & Client- Server Programming Spring 2016. Harold, Chapter 8: Sockets for Clients
CISC 4700 L01 Network & Client- Server Programming Spring 2016 Harold, Chapter 8: Sockets for Clients Datagram: Internet data packet Header: accounting info (e.g., address, port of source and dest) Payload:
D06 PROGRAMMING with JAVA
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch16 Files and Streams PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for
Java Programming: Sockets in Java
Java Programming: Sockets in Java Manuel Oriol May 10, 2007 1 Introduction Network programming is probably one of the features that is most used in the current world. As soon as people want to send or
Chapter 2 Application Layer. Lecture 5 FTP, Mail. Computer Networking: A Top Down Approach
Chapter 2 Application Layer Lecture 5 FTP, Mail Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012 Application Layer 2-1 Chapter 2: outline 2.1 principles
Domain Name System (DNS) Omer F. Rana. Networks and Data Communications 1
Domain Name System (DNS) Omer F. Rana Networks and Data Communications 1 What is a DNS Each institution on the internet has a host that runs a process called a Domain Name Server (also DNS!) It is not
CS 121 Intro to Programming:Java - Lecture 11 Announcements
CS 121 Intro to Programming:Java - Lecture 11 Announcements Next Owl assignment up, due Friday (it s short!) Programming assignment due next Monday morning Preregistration advice: More computing? Take
Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.
Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void
Applications and Services. DNS (Domain Name System)
Applications and Services DNS (Domain Name Service) File Transfer Protocol (FTP) Simple Mail Transfer Protocol (SMTP) Malathi Veeraraghavan Distributed database used to: DNS (Domain Name System) map between
File I/O - Chapter 10. Many Stream Classes. Text Files vs Binary Files
File I/O - Chapter 10 A Java stream is a sequence of bytes. An InputStream can read from a file the console (System.in) a network socket an array of bytes in memory a StringBuffer a pipe, which is an OutputStream
Internet Technologies. World Wide Web (WWW) Proxy Server Network Address Translator (NAT)
Internet Technologies World Wide Web (WWW) Proxy Server Network Address Translator (NAT) What is WWW? System of interlinked Hypertext documents Text, Images, Videos, and other multimedia documents navigate
CS43: Computer Networks Email. Kevin Webb Swarthmore College September 24, 2015
CS43: Computer Networks Email Kevin Webb Swarthmore College September 24, 2015 Three major components: mail (MUA) mail transfer (MTA) simple mail transfer protocol: SMTP User Agent a.k.a. mail reader composing,
The Application Layer: DNS
Recap SMTP and email The Application Layer: DNS Smith College, CSC 9 Sept 9, 0 q SMTP process (with handshaking) and message format q Role of user agent access protocols q Port Numbers (can google this)
AVRO - SERIALIZATION
http://www.tutorialspoint.com/avro/avro_serialization.htm AVRO - SERIALIZATION Copyright tutorialspoint.com What is Serialization? Serialization is the process of translating data structures or objects
Socket-based Network Communication in J2SE and J2ME
Socket-based Network Communication in J2SE and J2ME 1 C/C++ BSD Sockets in POSIX POSIX functions allow to access network connection in the same way as regular files: There are special functions for opening
The difference between TCP/IP, UDP/IP and Multicast sockets. How servers and clients communicate over sockets
Network Programming Topics in this section include: What a socket is What you can do with a socket The difference between TCP/IP, UDP/IP and Multicast sockets How servers and clients communicate over sockets
Network Programming using sockets
Network Programming using sockets TCP/IP layers Layers Message Application Transport Internet Network interface Messages (UDP) or Streams (TCP) UDP or TCP packets IP datagrams Network-specific frames Underlying
CPSC 360 - Network Programming. Email, FTP, and NAT. http://www.cs.clemson.edu/~mweigle/courses/cpsc360
CPSC 360 - Network Programming E, FTP, and NAT Michele Weigle Department of Computer Science Clemson University [email protected] April 18, 2005 http://www.cs.clemson.edu/~mweigle/courses/cpsc360
What is an I/O Stream?
Java I/O Stream 1 Topics What is an I/O stream? Types of Streams Stream class hierarchy Control flow of an I/O operation using Streams Byte streams Character streams Buffered streams Standard I/O streams
Communicating with a Barco projector over network. Technical note
Communicating with a Barco projector over network Technical note MED20080612/00 12/06/2008 Barco nv Media & Entertainment Division Noordlaan 5, B-8520 Kuurne Phone: +32 56.36.89.70 Fax: +32 56.36.883.86
2057-15. First Workshop on Open Source and Internet Technology for Scientific Environment: with case studies from Environmental Monitoring
2057-15 First Workshop on Open Source and Internet Technology for Scientific Environment: with case studies from Environmental Monitoring 7-25 September 2009 TCP/IP Networking Abhaya S. Induruwa Department
13 File Output and Input
SCIENTIFIC PROGRAMMING -1 13 File Output and Input 13.1 Introduction To make programs really useful we have to be able to input and output data in large machinereadable amounts, in particular we have to
Limi Kalita / (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 5 (3), 2014, 4802-4807. Socket Programming
Socket Programming Limi Kalita M.Tech Student, Department of Computer Science and Engineering, Assam Down Town University, Guwahati, India. Abstract: The aim of the paper is to introduce sockets, its deployment
CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus
CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus 1. Purpose This assignment exercises how to write a peer-to-peer communicating program using non-blocking
Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.
Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input
Simple Mail Transfer Protocol
Page 1 of 6 Home : Network Programming Simple Mail Transfer Protocol Contents What is SMTP? Basics of SMTP SMTP Commands Relaying of Messages Time Stamps and Return Path in Message Header Mail Exchangers
CS 1302 Ch 19, Binary I/O
CS 1302 Ch 19, Binary I/O Sections Pages Review Questions Programming Exercises 19.1-19.4.1, 19.6-19.6 710-715, 724-729 Liang s Site any Sections 19.1 Introduction 1. An important part of programming is
1. When will an IP process drop a datagram? 2. When will an IP process fragment a datagram? 3. When will a TCP process drop a segment?
Questions 1. When will an IP process drop a datagram? 2. When will an IP process fragment a datagram? 3. When will a TCP process drop a segment? 4. When will a TCP process resend a segment? CP476 Internet
1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius
Programming Concepts Practice Test 1 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius 2) Consider the following statement: System.out.println("1
TCP/IP and the Internet
TCP/IP and the Internet Computer networking today is becoming more and more entwined with the internet. By far the most popular protocol set in use is TCP/IP (Transmission Control Protocol/Internet Protocol).
JAVA Program For Processing SMS Messages
JAVA Program For Processing SMS Messages Krishna Akkulu The paper describes the Java program implemented for the MultiModem GPRS wireless modem. The MultiModem offers standards-based quad-band GSM/GPRS
DNS: Domain Names. DNS: Domain Name System. DNS: Root name servers. DNS name servers
DNS: Domain Name System DNS: Domain Names People: many identifiers: SSN, name, Passport # Internet hosts, routers: Always: IP address (32 bit) - used for addressing datagrams Often: name, e.g., nifc14.wsu.edu
Sample CSE8A midterm Multiple Choice (circle one)
Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names
Evolution of the WWW. Communication in the WWW. WWW, HTML, URL and HTTP. HTTP Abstract Message Format. The Client/Server model is used:
Evolution of the WWW Communication in the WWW World Wide Web (WWW) Access to linked documents, which are distributed over several computers in the History of the WWW Origin 1989 in the nuclear research
Files and input/output streams
Unit 9 Files and input/output streams Summary The concept of file Writing and reading text files Operations on files Input streams: keyboard, file, internet Output streams: file, video Generalized writing
Chapter 27 Hypertext Transfer Protocol
Chapter 27 Hypertext Transfer Protocol Columbus, OH 43210 [email protected] http://www.cis.ohio-state.edu/~jain/ 27-1 Overview Hypertext language and protocol HTTP messages Browser architecture CGI
Internet Technology 2/13/2013
Internet Technology 03r. Application layer protocols: email Email: Paul Krzyzanowski Rutgers University Spring 2013 1 2 Simple Mail Transfer Protocol () Defined in RFC 2821 (April 2001) Original definition
Cross-platform TCP/IP Socket Programming in REXX
Cross-platform TCP/IP Socket programming in REXX Abstract: TCP/IP is the key modern network technology, and the various REXX implementations have useful, if incompatible interfaces to it. In this session,
Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture #3 2008 3 Apache.
JSP, and JSP, and JSP, and 1 2 Lecture #3 2008 3 JSP, and JSP, and Markup & presentation (HTML, XHTML, CSS etc) Data storage & access (JDBC, XML etc) Network & application protocols (, etc) Programming
File Transfer Protocol (FTP) Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology Fall 2007, TAIWAN
File Transfer Protocol (FTP) Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology Fall 2007, TAIWAN 1 Contents CONNECTIONS COMMUNICATION COMMAND PROCESSING
Linux MPS Firewall Supplement
Linux MPS Firewall Supplement First Edition April 2007 Table of Contents Introduction...1 Two Options for Building a Firewall...2 Overview of the iptables Command-Line Utility...2 Overview of the set_fwlevel
TCP/IP Networking An Example
TCP/IP Networking An Example Introductory material. This module illustrates the interactions of the protocols of the TCP/IP protocol suite with the help of an example. The example intents to motivate the
JAVA - FILES AND I/O
http://www.tutorialspoint.com/java/java_files_io.htm JAVA - FILES AND I/O Copyright tutorialspoint.com The java.io package contains nearly every class you might ever need to perform input and output I/O
Evolution of the WWW. Communication in the WWW. WWW, HTML, URL and HTTP. HTTP - Message Format. The Client/Server model is used:
Evolution of the WWW Communication in the WWW World Wide Web (WWW) Access to linked documents, which are distributed over several computers in the History of the WWW Origin 1989 in the nuclear research
WRITING DATA TO A BINARY FILE
WRITING DATA TO A BINARY FILE TEXT FILES VS. BINARY FILES Up to now, we have looked at how to write and read characters to and from a text file. Text files are files that contain sequences of characters.
Intel Retail Client Manager Audience Analytics
Intel Retail Client Manager Audience Analytics By using this document, in addition to any agreements you have with Intel, you accept the terms set forth below. You may not use or facilitate the use of
SSC - Communication and Networking Java Socket Programming (II)
SSC - Communication and Networking Java Socket Programming (II) Shan He School for Computational Science University of Birmingham Module 06-19321: SSC Outline Outline of Topics Multicast in Java User Datagram
Cape Girardeau Career Center CISCO Networking Academy Bill Link, Instructor. 2.,,,, and are key services that ISPs can provide to all customers.
Name: 1. What is an Enterprise network and how does it differ from a WAN? 2.,,,, and are key services that ISPs can provide to all customers. 3. Describe in detail what a managed service that an ISP might
Course Overview: Learn the essential skills needed to set up, configure, support, and troubleshoot your TCP/IP-based network.
Course Name: TCP/IP Networking Course Overview: Learn the essential skills needed to set up, configure, support, and troubleshoot your TCP/IP-based network. TCP/IP is the globally accepted group of protocols
Novell Identity Manager
AUTHORIZED DOCUMENTATION Manual Task Service Driver Implementation Guide Novell Identity Manager 4.0.1 April 15, 2011 www.novell.com Legal Notices Novell, Inc. makes no representations or warranties with
Java CPD (I) Frans Coenen Department of Computer Science
Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials
CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
Product Standard General Interworking: Internet Server
General Interworking: Internet Server The Open Group Copyright August 1998, The Open Group All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
An Overview of Java. overview-1
An Overview of Java overview-1 Contents What is Java Major Java features Java virtual machine Java programming language Java class libraries (API) GUI Support in Java Networking and Threads in Java overview-2
Chakchai So-In, Ph.D.
Application Layer Functionality and Protocols Chakchai So-In, Ph.D. Khon Kaen University Department of Computer Science Faculty of Science, Khon Kaen University 123 Mitaparb Rd., Naimaung, Maung, Khon
1 Data information is sent onto the network cable using which of the following? A Communication protocol B Data packet
Review questions 1 Data information is sent onto the network cable using which of the following? A Communication protocol B Data packet C Media access method D Packages 2 To which TCP/IP architecture layer
When the transport layer tries to establish a connection with the server, it is blocked by the firewall. When this happens, the RMI transport layer
Firewall Issues Firewalls are inevitably encountered by any networked enterprise application that has to operate beyond the sheltering confines of an Intranet Typically, firewalls block all network traffic,
Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language
Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description
CS 164 Winter 2009 Term Project Writing an SMTP server and an SMTP client (Receiver-SMTP and Sender-SMTP) Due & Demo Date (Friday, March 13th)
CS 164 Winter 2009 Term Project Writing an SMTP server and an SMTP client (Receiver-SMTP and Sender-SMTP) Due & Demo Date (Friday, March 13th) YOUR ASSIGNMENT Your assignment is to write an SMTP (Simple
Protocolo HTTP. Web and HTTP. HTTP overview. HTTP overview
Web and HTTP Protocolo HTTP Web page consists of objects Object can be HTML file, JPEG image, Java applet, audio file, Web page consists of base HTML-file which includes several referenced objects Each
