ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/XMLReader/XMLSender.java
Revision: 1.3
Committed: Fri Nov 17 14:45:56 2000 UTC (23 years, 11 months ago) by pjm2
Branch: MAIN
Changes since 1.2: +1 -2 lines
Log Message:
Fixed a major parsing problem by wrapping the XML in an InputSource object
and removing null characters from the input.  Also modified the XMLSender
class so that it no longer sent "null" when the last line of an input file
is reached.

File Contents

# User Rev Content
1 pjm2 1.1 import java.io.*;
2     import java.net.*;
3     import java.util.*;
4    
5     // Class used to send arbitrary crap to the XMLReader
6    
7     public class XMLSender {
8     public static void main(String[] args) throws IOException {
9    
10 pjm2 1.2 if (args.length != 2) {
11     System.out.println("Usage: java XMLSender <hostname> <filename.xml>");
12 pjm2 1.1 }
13    
14 pjm2 1.2 int port = 4589;
15    
16 pjm2 1.1 // stuff to send
17 pjm2 1.2 BufferedReader br = new BufferedReader(new FileReader(args[1]));
18     String xml = "";
19     String line = br.readLine();
20     while (line != null){
21 pjm2 1.3 xml += line;
22 pjm2 1.2 line = br.readLine();
23     }
24 pjm2 1.1
25     // get a datagram socket
26     DatagramSocket socket = new DatagramSocket();
27    
28     // send request
29 pjm2 1.2 byte[] buf = xml.getBytes();
30 pjm2 1.1 InetAddress address = InetAddress.getByName(args[0]);
31 pjm2 1.2 DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port);
32 pjm2 1.1 socket.send(packet);
33    
34     String dataOut = new String(packet.getData());
35 pjm2 1.2 System.out.println("Sending the following: " + dataOut);
36 pjm2 1.1
37     socket.close();
38     }
39     }