Java Network Programming. 1. Java Network Programming. Reader 1. Learning
Java Programming By Examples. Dr. Wanlei Zhou ...
It covers most, if not all, aspects of Java network programming facilities. First, the
lower level Java networking is overviewed which includes communication with ...
CSCE 515: Computer Network. Programming. ------ Java Network Programming
reference: Dave Hollinger. Wenyuan Xu. Department of Computer Science and.
Internet, Web applications, and Web services, the majority of today's programs and applications require ... basic concep
COMP201 Topic 2 / Slide 2. Objective and Outline. â Objective. â« Show basic programming concepts. â Outline. â« W
... 100 programming examples of Object Oriented Programming C Starting from ... amity school of engineering amp technolo
Network Programming. • Based on the java.net package. • Classes for socket and
for URL (Uniform Resource Locator) management. • With the help of URLs ...
Advanced Network Programming Lab using Java. Angelos ... Network
Programming Handbook. 2 ... new BufferedReader(new InputStreamReader(
System.in));.
Network programming in Java in general much easier than in C... ▫ ...except
some advanced things which are harder ☹. ▫ Setting socket options, no select()-
call.
Sun, Sun Microsystems, the Sun Logo, the Java programming language, J2SE
5.0, and ... Surprisingly, the market in Java network programming texts is a much
...
Network programming in Java using Socket. Abhijit A. Sawant, Dr. B. B. Meshram
. Department of Computer Technology, Veermata Jijabai Technological Institute.
PDF online, PDF new Introduction to Java Programming: Brief Version, 10th Edition, Online PDF Introduction to Java Progr
concepts of problem- solving and object- oriented programming using a fundamentals- first approach. Beginning programmer
Jun 1, 2001 - the examples, you may have to add one or both of these import ..... A unifying theme underlies this Item a
PDF Download Introduction To Java Programming, Comprehensive Version (9th Edition) By Y. Daniel ... Edition) By Y. Danie
PDF Download Introduction To Java Programming, Comprehensive Version (9th Edition) By Y. Daniel Liang Full Ebook,PDF Fre
languages such as Java, Pascal, or C++. A program written in a ...... If I say âthe President went fishing,â I mean
In this book you'll see popular design patterns, such as decorator, builder, and ... pick up techniques to implement des
Broadband connections to the Internet, such as DSL and cable modems, are .... But applets are only one aspect of Java's
Edition - Read Unlimited eBooks and Audiobooks - By Y. Daniel ... Version Plus MyProgrammingLab with Pearson eText Acces
Programming: Brief Version, 10th Edition Free PDF Online, Introduction to Java .... replaced Swing as the new GUI tool f
... to articles tutorials online books and software downloads helps you find what you ... Discover the power of Java for
(Programming Series), read online free Simply Java: An Introduction to Java ... postponed until after the student has a
Sockets in Java TCP Sockets UDP Sockets Multithreading
The Sockets Interface To communicate you have to connect the two ends
Sockets in Java The sockets API is available in many languages Protocol stack is part of most Operating Systems Java provides a clean and easy access to the sockets
A socket is an end-point
Socket Address Two kinds of sockets: tcp & udp Each socket: IP address port number
Java Sockets Socket classes belong to java.net package Socket, ServerSocket & DatagramSocket Each type works quite differently Java help is your friend: read it
TCP client Client starts the connection the server Socket s=new Socket(“hostname”,25); Connection is closed by: s.close(); Something else in between is desired!
Socket Input/Output TCP provides a data stream Byte-oriented vs. line-oriented I/O Scanner & PrintWriter InputStream & OutputStream UDP exchanges byte arrays only
Exception handling Some methods can cause Exceptions Exceptions may be caught to be handled by your code Exceptions can be thrown not to be handled by your code try/catch vs throws clauses
Basic TCP client It connects to a web server It sends a request It receives and prints the response import java.net.*; import java.io.*; import java.util.*; class ClientTCP { public static void main(String args[]) throws UnknownHostException, IOException { ! Socket s=new Socket("www.upv.es",80); ! Scanner in=new Scanner(s.getInputStream()); ! PrintWriter out=new PrintWriter(s.getOutputStream(),true); ! out.println("GET / HTTP/1.0"); ! out.println(); ! while(in.hasNext()) System.out.println(in.nextLine()); ! } }
Basic TCP server Server waits for a new connection from a client Server transmits a message to the client and closes the connection Repeat
Several clients can be server AT ONCE Use of fork Use of Threads (Java)
cli1 cli2 cli3
server
Threads in Java Your class extends Thread class Code of thread is defined on run() method start() method call will start running a new thread of excution class MyThread extends Thread { public void run() { // thread code here while(true) System.out.print("T"); } public static void main(String args[]) { Thread t = new MyThread(); t.start(); while(true) System.out.print("M"); } }
Basic Concurrent Server What is the difference from basic server? import java.net.*; import java.io.*; import java.util.*; class CServerTCP extends Thread { PrintWriter myOut=null; public CServerTCP(PrintWriter out) { myOut=out; } public void run() {myOut.println("Hello Client!"); } public static void main(String args[]) throws UnknownHostException, IOException { ! ServerSocket ss = new ServerSocket(8888); ! while(true) { ! ! Socket s = ss.accept(); ! ! Scanner in=new Scanner(s.getInputStream()); ! ! PrintWriter out=new PrintWriter(s.getOutputStream(),true); ! ! new CServerTCP(out).start(); ! ! } ! } }
UDP Sockets DatagramSocket sends/receives DatagramPacket objects A DatagramPacket has a data buffer in the form of a byte array Destination address is defined for each DatagramPacket (remember: no connection here!)
Sample UDP sender Addresses are expressed as InetAddress Buffer length changes with content nc -u -l 7777 import java.net.*; import java.io.*; import java.util.*; class UDPsender { public static void main(String args[]) throws UnknownHostException, IOException { ! DatagramSocket ds = new DatagramSocket(12345); ! byte buffer[] = new String("Hello World!\n").getBytes(); ! InetAddress dst = InetAddress.getByName("127.0.0.1"); ! DatagramPacket dp = new DatagramPacket(buffer,buffer.length,dst,7777); ! ds.send(dp);! ! } }
UDP echo server Returns datagram back to the sender import java.net.*; import java.io.*; import java.util.*; class UDPecho { public static void main(String args[]) throws UnknownHostException, IOException { ! DatagramSocket ds = new DatagramSocket(12345); ! byte buffer[] = new byte[1024]; ! DatagramPacket dp = new DatagramPacket(buffer,buffer.length); ! for(;;) { ! ! ds.receive(dp);! ! ! dp.setAddress(dp.getAddress()); // back to the sender ! ! dp.setPort(dp.getPort()); ! ! ds.send(dp); ! ! } ! } }
Multiprotocol server Several protocols are handled by the same server program It can be like an extended concurrent server with serveral types of threads