CS 491, 591 Networking in Java Summer 2007. Establishing a Simple Server (Using Stream Sockets) Creating a Java server –Create ServerSocket object ServerSocket.

Slides:



Advertisements
Similar presentations
Socket UDP H. Fauconnier 1-1 M2-Internet Java. UDP H. Fauconnier M2-Internet Java 2.
Advertisements

SOCKET PROGRAMMING WITH MOBILE SOCKET CLIENT DEARTMENT OF COMPUTER SCIENCE IOWA STATE UNIVERSITY.
Jan Java Networking UDP Yangjun Chen Dept. Business Computing University of Winnipeg.
2: Application Layer 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
User Datagram Protocol. Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive.
 Pearson Education, Inc. All rights reserved. 1 CH24 Networking : OBJECTIVES In this chapter you will learn:  To understand Java networking.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
 Pearson Education, Inc. All rights reserved Networking.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Networking. Introduction In this lecture –Swing GUI component JEditorPane (view HTML docs) –Socket-based communications View networking like file I/O.
1 Network Layers Application Transport Network Data-Link Physical bits.
 2002 Prentice Hall, Inc. All rights reserved. 1 Week 5 - Networking Outline 5.1 Introduction 5.2 Manipulating URLs 5.3 Reading a File on a Web Server.
Networking. Introduction In this chapter –Swing GUI component JEditorPane (view HTML docs) –Socket-based communications View networking like file I/O.
Io package as Java’s basic I/O system continue’d.
2: Application Layer 1 Socket Programming TCP and UDP.
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
Babak Esfandiari (based on slides by Qusay Mahmoud)
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
Cli/Serv.: jnet/111 Client/Server Distributed Systems v Objectives –describe basic networking in Java – Web page retrieval and sockets programming.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
VIII. UDP Datagrams and Sockets. The User Datagram Protocol (UDP) is an alternative protocol for sending data over IP that is very quick, but not reliable:
-1- Georgia State UniversitySensorweb Research Laboratory CSC4220/6220 Computer Networks Dr. WenZhan Song Associate Professor, Computer Science.
Socket Programming Lee, Sooyong
Network Programming and Sockets CPSC 363 Computer Networks Ellen Walker Hiram College (Includes figures from Computer Networking by Kurose & Ross, © Addison.
Socket Programming Tutorial. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
Java Sockets Programming
Java Socket programming. Socket programming with TCP.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
2: Application Layer1 Socket programming Socket API Explicitly created, used, released by apps Client/server paradigm Two types of transport service via.
1 CSCD 330 Network Programming Spring 2014 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 7 Application.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 18 - Networking Outline 18.1 Introduction 18.2 Manipulating URLs 18.3 Reading a File on a Web.
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Java Programming II Java Network (I) Java Programming II.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
 2002 Prentice Hall, Inc. All rights reserved. 1 Chapter 17 - Networking Outline 17.1 Introduction 17.2 Manipulating URLs 17.3 Reading a File on a Web.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Networking OSI (Open Systems Interconnection) model of computer networking, seven layers (the Application, Presentation, Session, Transport, Network, Data.
SOCKET PROGRAMMING WITH JAVA By Collin Donaldson.
 2002 Prentice Hall, Inc. All rights reserved Introduction Networking package is java.net –Socket-based communications Applications view networking.
Network Programming. These days almost all devices.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Network Programming Communication between processes Many approaches:
Java 13. Networking public class SumTest {
Network Programming Introduction
Networking.
Socket programming - Java
CSCD 330 Network Programming
Socket Programming.
CSCD 330 Network Programming
COP 4610L: Applications in the Enterprise Spring 2005
Socket Programming 2: Application Layer.
CPSC 441 UDP Socket Programming
Chapter 2: Application layer
CS18000: Problem Solving and Object-Oriented Programming
Java Chapter 4 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

CS 491, 591 Networking in Java Summer 2007

Establishing a Simple Server (Using Stream Sockets) Creating a Java server –Create ServerSocket object ServerSocket s = new ServerSocket( port, queueLength ); Register port number and set max number of waiting clients Binds server to port, waits for clients –Server listens indefinitely (blocks) for clients Socket connection = s.accept() Connections managed by Socket objects Returns Socket when connection established

Establishing a Simple Client (Using Stream Sockets) Creating a Java server –Get I/O objects for communication OutputStream - sends info to client InputStream - gets info from client Server's input stream is client's output stream, and vice versa –Use Socket object to get references to streams connection.getInputStream() connection.getOutputStream() –Methods write and read Send individual bytes

Establishing a Simple Client (Using Stream Sockets) Creating a Java server –Chaining stream types (sending objects and data, not bytes) ObjectInputStream input = new ObjectInputStream( connection.getInputStream() ) –Processing phase Server/client communicate using InputStream and OutputStream –Termination Transmission complete Method close (of Socket ) connection.close() –Networking appears as sequential file I/O Sockets simplify networking

Establishing a Simple Client (Using Stream Sockets) Creating a Java client –Create Socket to connect to server Socket connection = new Socket( serverAddress, port ) If successful, returns Socket –Else throws subclass of IOException –Get stream objects connection.getInputStream() connection.getOutputStream() Use chaining if transmitting objects and data, not pure bytes –ObjectInputStream, ObjectOutputStream

Establishing a Simple Client (Using Stream Sockets) Creating a Java client –Processing phase Communicate using stream objects –Termination Transmission complete connection.close() (close Socket ) –Client must determine when server done read returns -1 when eof found ObjectInputStream generates EOFException

Client/Server Interaction with Stream Socket Connections Upcoming program –Simple client/server chat application –Use stream sockets –Client connects, transmit String objects do-while loop to get input Event handler calls sendData method to send output –When either sends TERMINATE, connection terminates Server waits for next client –GUI:

Client/Server Interaction with Stream Socket Connections Server –Once connection ( Socket ) established getInetAddress() - returns InetAddress object getHostName() - returns client's host name –Create ObjectOutputStream flush() –Sends stream header to client –Required by client's ObjectInputStream 63 output = new ObjectOutputStream( 64 connection.getOutputStream() ); 65 output.flush(); 60 connection.getInetAddress().getHostName() );

Client/Server Interaction with Stream Socket Connections –Send/receive data Method sendData called by event handler Buffer flushed after every transmission –Sets cursor position to end of text Allows JTextArea to scroll with text –Server processes single connection at a time More likely to have separate threads for each connection 108 private void sendData( String s ) 109 { 111 output.writeObject( "SERVER>>> " + s ); 112 output.flush(); 113 display.append( "\nSERVER>>>" + s ); 81 display.setCaretPosition( 82 display.getText().length() );

1. Constructor 1.1 GUI components 1// Fig. 21.3: Server.java 2// Set up a Server that will receive a connection 3// from a client, send a string to the client, 4// and close the connection. 5import java.io.*; 6import java.net.*; 7import java.awt.*; 8import java.awt.event.*; 9import javax.swing.*; 10 11public class Server extends JFrame { 12 private JTextField enter; 13 private JTextArea display; 14 ObjectOutputStream output; 15 ObjectInputStream input; public Server() 18 { 19 super( "Server" ); Container c = getContentPane(); enter = new JTextField(); 24 enter.setEnabled( false );

1.2 Event handler 1.3 GUI 2. Method runServer 2.1 ServerSocket display = new JTextArea(); 36 c.add( new JScrollPane( display ), 37 BorderLayout.CENTER ); setSize( 300, 150 ); 40 show(); 41 } public void runServer() 44 { 45 ServerSocket server; 46 Socket connection; 47 int counter = 1; try { 50 // Step 1: Create a ServerSocket server = new ServerSocket( 5000, 100 ); enter.addActionListener( 26 new ActionListener() { 27 public void actionPerformed( ActionEvent e ) 28 { sendData( e.getActionCommand() ); 30 } 31 } 32 ); 33 c.add( enter, BorderLayout.NORTH ); The event handlers calls method sendData, using text in JTextField as argument. Register port 5000, server will allow 100 clients to wait in queue.

2.2 accept 2.3 getHostName 2.4 Get streams 2.5 writeObject 2.6 Loop 67 connection.getInputStream() ); 68 display.append( "\nGot I/O streams\n" ); // Step 4: Process connection. 71 String message = 72 "SERVER>>> Connection successful"; 73 output.writeObject( message ); 74 output.flush(); 75 enter.setEnabled( true ); do { 78 try { 79 message = (String) input.readObject(); 80 display.append( "\n" + message ); 81 display.setCaretPosition( 82 display.getText().length() ); 83 } while ( true ) { 54 // Step 2: Wait for a connection. 55 display.setText( "Waiting for connection\n" ); connection = server.accept(); display.append( "Connection " + counter + 59 " received from: " connection.getInetAddress().getHostName() ); // Step 3: Get input and output streams output = new ObjectOutputStream( 64 connection.getOutputStream() ); 65 output.flush(); 66 input = new ObjectInputStream( Infinite loop to wait for connections from clients. Wait for connection ( server.accept() waits indefinitely). Display host location. Set up I/O streams, flush buffer (sends stream data). Send confirmation message. Loop to get input. Set cursor to end of text.

2.6 Loop 2.7 close 3. Method sendData 3.1 writeObject 3.2 flush 100 catch ( EOFException eof ) { 101 System.out.println( "Client terminated connection" ); 102 } 103 catch ( IOException io ) { 104 io.printStackTrace(); 105 } 106 } private void sendData( String s ) 109 { 110 try { output.writeObject( "SERVER>>> " + s ); 112 output.flush(); 113 display.append( "\nSERVER>>>" + s ); 114 } 84 catch ( ClassNotFoundException cnfex ) { 85 display.append( 86 "\nUnknown object type received" ); 87 } } while ( !message.equals( "CLIENT>>> TERMINATE" ) ); // Step 5: Close connection. 91 display.append( "\nUser terminated connection" ); 92 enter.setEnabled( false ); output.close(); 94 input.close(); 95 connection.close(); counter; 98 } 99 } Loop until TERMINATE string sent. Close connection and I/O streams. Send String object to client. Flush buffer to ensure it is sent, and update server's display.

4. main app.runServer(); 135 } 136} 115 catch ( IOException cnfex ) { 116 display.append( 117 "\nError writing object" ); 118 } 119 } public static void main( String args[] ) 122 { 123 Server app = new Server(); app.addWindowListener( 126 new WindowAdapter() { 127 public void windowClosing( WindowEvent e ) 128 { 129 System.exit( 0 ); 130 } 131 } 132 );

Client/Server Interaction with Stream Socket Connections Client –Similar to server –Creates same GUI –Loops to wait for input Sends output through event handler and sendData

Client/Server Interaction with Stream Socket Connections –Create Socket with two arguments Internet address of server and port number –static method getByName (Class InetAddress ) Returns InetAddress object Takes String Could have taken "localhost" or called static method getLocalHost –Create I/O objects as before Output of server is input of client 50 client = new Socket( 51 InetAddress.getByName( " " ), 5000 );

1. Constructor 1.1 GUI 1// Fig. 21.4: Client.java 2// Set up a Client that will read information sent 3// from a Server and display the information. 4import java.io.*; 5import java.net.*; 6import java.awt.*; 7import java.awt.event.*; 8import javax.swing.*; 9 10public class Client extends JFrame { 11 private JTextField enter; 12 private JTextArea display; 13 ObjectOutputStream output; 14 ObjectInputStream input; 15 String message = ""; public Client() 18 { 19 super( "Client" ); Container c = getContentPane(); enter = new JTextField(); 24 enter.setEnabled( false );

1.2 Event handler 1.3 GUI 2. Method runClient 2.1 Socket display = new JTextArea(); 36 c.add( new JScrollPane( display ), 37 BorderLayout.CENTER ); setSize( 300, 150 ); 40 show(); 41 } public void runClient() 44 { 45 Socket client; try { 48 // Step 1: Create a Socket to make connection. 49 display.setText( "Attempting connection\n" ); 50 client = new Socket( 51 InetAddress.getByName( " " ), 5000 ); enter.addActionListener( 26 new ActionListener() { 27 public void actionPerformed( ActionEvent e ) 28 { sendData( e.getActionCommand() ); 30 } 31 } 32 ); 33 c.add( enter, BorderLayout.NORTH ); Client gets text from JTextField and calls sendData. Create Socket to server, make connection.

2.2 I/O streams 2.3 flush 2.4 Loop 67 // Step 3: Process connection. 68 enter.setEnabled( true ); do { 71 try { 72 message = (String) input.readObject(); 73 display.append( "\n" + message ); 74 display.setCaretPosition( 75 display.getText().length() ); 76 } 77 catch ( ClassNotFoundException cnfex ) { 78 display.append( 79 "\nUnknown object type received" ); 80 } 81 } while ( !message.equals( "SERVER>>> TERMINATE" ) ); display.append( "Connected to: " + 57 client.getInetAddress().getHostName() ); // Step 2: Get the input and output streams. 60 output = new ObjectOutputStream( 61 client.getOutputStream() ); output.flush(); 63 input = new ObjectInputStream( 64 client.getInputStream() ); 65 display.append( "\nGot I/O streams\n" ); 66 Code similar to server. Create I/O objects, flush buffer, loop to wait for and process input.

2.5 close 3. Method sendData 100 message = s; 101 output.writeObject( "CLIENT>>> " + s ); 102 output.flush(); 103 display.append( "\nCLIENT>>>" + s ); 104 } 105 catch ( IOException cnfex ) { 106 display.append( 107 "\nError writing object" ); 108 } 109 } // Step 4: Close connection. 84 display.append( "Closing connection.\n" ); 85 input.close(); 86 output.close(); 87 client.close(); 88 } 89 catch ( EOFException eof ) { 90 System.out.println( "Server terminated connection" ); 91 } 92 catch ( IOException e ) { 93 e.printStackTrace(); 94 } 95 } private void sendData( String s ) 98 { 99 try {

4. main Program Output 111 public static void main( String args[] ) 112 { 113 Client app = new Client(); app.addWindowListener( 116 new WindowAdapter() { 117 public void windowClosing( WindowEvent e ) 118 { 119 System.exit( 0 ); 120 } 121 } 122 ); app.runClient(); 125 } 126} 127

Program Output

Connectionless Client/Server Interaction with Datagrams Connection-oriented interaction –Like phone call Have connection to other end Connection maintained for duration of call, even if not talking Connectionless interaction –Like sending postal mail –Use datagrams, packets of data –If large packet, break into smaller pieces Send separately May arrive out of order or not arrive at all Duplicates may arrive

Connectionless Client/Server Interaction with Datagrams –DatagramSocket( port ) Binds server to port –DatagramPacket( byteArray, byteArray.length ) Create DatagramPacket to store received packet byteArray stores data –Method receive( packetToStore ) Blocks until packet arrives, stores in packetToStore 27 socket = new DatagramSocket( 5000 ); 40 byte data[] = new byte[ 100 ]; 41 receivePacket = 42 new DatagramPacket( data, data.length ); 45 socket.receive( receivePacket );

Connectionless Client/Server Interaction with Datagrams –getAddress - returns InetAddress –getPort, getLength - return integers –getData - returns byte array Used in String constructor to create string 48 display.append( "\nPacket received:" + 49 "\nFrom host: " + receivePacket.getAddress() + 50 "\nHost port: " + receivePacket.getPort() + 51 "\nLength: " + receivePacket.getLength() + 52 "\nContaining:\n\t" + 53 new String( receivePacket.getData(), 0, 54 receivePacket.getLength() ) );

Connectionless Client/Server Interaction with Datagrams –Echo packet back to client DatagramPacket( byteArray, length, InetAddress, port ) Method send( packetToSend ) 58 sendPacket = 59 new DatagramPacket( receivePacket.getData(), 60 receivePacket.getLength(), 62 receivePacket.getPort() ); 63 socket.send( sendPacket ); 61 receivePacket.getAddress(),

1. Declarations 1.1 DatagramSocket 1// Fig. 21.5: Server.java 2// Set up a Server that will receive packets from a 3// client and send packets to a client. 4import java.io.*; 5import java.net.*; 6import java.awt.*; 7import java.awt.event.*; 8import javax.swing.*; 9 10public class Server extends JFrame { 11 private JTextArea display; private DatagramPacket sendPacket, receivePacket; 14 private DatagramSocket socket; public Server() 17 { 18 super( "Server" ); display = new JTextArea(); 21 getContentPane().add( new JScrollPane( display), 22 BorderLayout.CENTER ); 23 setSize( 400, 300 ); 24 show(); try { 27 socket = new DatagramSocket( 5000 ); 28 } Create new DatagramSocket, binds server to port.

2. Method waitForPackets 2.1 receivePacket 2.2 receive 2.3 Process packet 2.4 Echo packet public void waitForPackets() 36 { while ( true ) { 38 try { 39 // set up packet 40 byte data[] = new byte[ 100 ]; 41 receivePacket = new DatagramPacket( data, data.length ); // wait for packet 45 socket.receive( receivePacket ); // process packet 48 display.append( "\nPacket received:" + 49 "\nFrom host: " + receivePacket.getAddress() + 50 "\nHost port: " + receivePacket.getPort() + 51 "\nLength: " + receivePacket.getLength() + 52 "\nContaining:\n\t" new String( receivePacket.getData(), 0, 54 receivePacket.getLength() ) ); // echo information from packet back to client 57 display.append( "\n\nEcho data to client..."); 29 catch( SocketException se ) { 30 se.printStackTrace(); 31 System.exit( 1 ); 32 } 33 } sendPacket = 59 new DatagramPacket( receivePacket.getData(), Create new DatagramPacket to receive info. Gather and display packet data. Convert byte array to a String. Create packet back to client.Loop to wait for packets.

2.5 send 3. main 67 } 68 catch( IOException io ) { 69 display.append( io.toString() + "\n" ); 70 io.printStackTrace(); 71 } 72 } 73 } public static void main( String args[] ) 76 { 77 Server app = new Server(); app.addWindowListener( 80 new WindowAdapter() { 81 public void windowClosing( WindowEvent e ) 82 { 83 System.exit( 0 ); 84 } 85 } 86 ); app.waitForPackets(); 89 } 90} 60 receivePacket.getLength(), 61 receivePacket.getAddress(), 62 receivePacket.getPort() ); socket.send( sendPacket ); 64 display.append( "Packet sent\n" ); 65 display.setCaretPosition( 66 display.getText().length() ); Send packet back to client.

Program Output

Connectionless Client/Server Interaction with Datagrams Client –Similar to server –Has JTextField Sends packets with event handler for JTextField Convert String to byteArray –String.getBytes() –Have loop to receive echoed packets from server –Constructor needs no arguments Uses next available port Server gets client's port number as part of DatagramPacket 31 socket = new DatagramSocket();

1. Constructor 1.1 GUI 1.2 Register event handler 1// Fig. 21.6: Client.java 2// Set up a Client that will send packets to a 3// server and receive packets from a server. 4import java.io.*; 5import java.net.*; 6import java.awt.*; 7import java.awt.event.*; 8import javax.swing.*; 9 10public class Client extends JFrame implements ActionListener { 11 private JTextField enter; 12 private JTextArea display; private DatagramPacket sendPacket, receivePacket; 15 private DatagramSocket socket; public Client() 18 { 19 super( "Client" ); enter = new JTextField( "Type message here" ); 22 enter.addActionListener( this ); 23 getContentPane().add( enter, BorderLayout.NORTH ); 24 display = new JTextArea(); 25 getContentPane().add( new JScrollPane( display ), 26 BorderLayout.CENTER ); 27 setSize( 400, 300 ); 28 show(); 29

1.3 DatagramSocket 2. waitForPackets 2.1 DatagramPacket 2.2 receive 2.3 Process packet 34 se.printStackTrace(); 35 System.exit( 1 ); 36 } 37 } public void waitForPackets() 40 { while ( true ) { 42 try { 43 // set up packet 44 byte data[] = new byte[ 100 ]; 45 receivePacket = 46 new DatagramPacket( data, data.length ); // wait for packet 49 socket.receive( receivePacket ); // process packet 52 display.append( "\nPacket received:" + 53 "\nFrom host: " + receivePacket.getAddress() + 54 "\nHost port: " + receivePacket.getPort() + 55 "\nLength: " + receivePacket.getLength() + 56 "\nContaining:\n\t" + 57 new String( receivePacket.getData(), 0, 58 receivePacket.getLength() ) ); 30 try { socket = new DatagramSocket(); 32 } 33 catch( SocketException se ) { No argument constructor.Similar to server, loop to receive echoed packets.

3. actionPerformed 3.1 Create packet 3.2 send 67 } public void actionPerformed( ActionEvent e ) 70 { 71 try { 72 display.append( "\nSending packet containing: " + 73 e.getActionCommand() + "\n" ); String s = e.getActionCommand(); byte data[] = s.getBytes(); sendPacket = new DatagramPacket( data, data.length, 79 InetAddress.getLocalHost(), 5000 ); 80 socket.send( sendPacket ); 81 display.append( "Packet sent\n" ); 82 display.setCaretPosition( 83 display.getText().length() ); } 86 catch ( IOException exception ) { 87 display.append( exception.toString() + "\n" ); 88 exception.printStackTrace(); 89 } 90 } 59 display.setCaretPosition( 60 display.getText().length() ); 61 } 62 catch( IOException exception ) { 63 display.append( exception.toString() + "\n" ); 64 exception.printStackTrace(); 65 } 66 } Convert String to a byte array, use to initialize DatagramPacket.

Program Output 100 System.exit( 0 ); 101 } 102 } 103 ); app.waitForPackets(); 106 } 107} public static void main( String args[] ) 93 { 94 Client app = new Client(); app.addWindowListener( 97 new WindowAdapter() { 98 public void windowClosing( WindowEvent e ) 99 {