Javanetworks - Java Network Programming • The

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Network Programming The package contains the Socket class. This class speaks TCP (connection-oriented protocol). The DatagramSocket class uses UDP (connectionless protocol). The class represents a single side of a socket connection on either the client or server. In addition, the server uses the class to wait for connections from clients. The server creates a ServerSocket object and waits, blocked in a call to its accept() method, until a connection arrives. When a connection request arrives, the accept() creates a Socket object. The server uses this Socket object to communicate with the client. E.g. of a client: try { Socket server = new Socket("", 2500); InputStream in = server.getInputStream(); OutputStream out = server.getOutputStream(); //sends a string PrintStream pout = new PrintStream(out); Pout.println("Hello!"); //Read a string DataInputStream din = new DataInputStream(in); String response = din.readLine(); Server.close(); } catch (IOException e) { System.out.println("Error connecting to host"); }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
E.g. of a server:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/29/2011 for the course CNT 6707 taught by Professor Ahuja during the Spring '11 term at UNF.

Page1 / 5

Javanetworks - Java Network Programming • The

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online