473,382 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Parsing with Java SAX from a UDP socket

I'm trying to accept UDP multicast XML messages and parse them. The current way I'm doing so is by creating a new File for each message and then calling parser.parse(filename.xml) This way works. However, I think the frequent File I/O is causing performance problems. Is there a way I can do this without doing File I/O? The parse() method allows an InputStream but I don't know how to get an InputStream. Here's my current code:

MulticastSocket s = new MulticastSocket(port);
s.joinGroup(InetAddress.getByName(group));

while(true){
byte[] buf = new byte[10240];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
s.receive(recv);

//a.xml is a temporary file where the message is written
String outFile = "a.xml";
File out_file = new File(outFile);
out_file.deleteOnExit();

FileOutputStream xml_temp = new FileOutputStream(out_file);
xml_temp.write(buf,0,recv.getLength());
try{
parser.parse(out_file, SAXHandler);
}
catch (Exception e)
{System.out.println("Parser had an error:" + e);}
}
Jan 18 '07 #1
0 1412

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dominique | last post by:
I am trying to communicate to a prolog server from a java client, however even though the connection is successfully made every time I try to perform QueryExecute I get an error, either Socket...
1
by: Krzysztof Pa¼ | last post by:
Hi, I want to make simple client in phyton, which would be able to communicate with Java server using SSL sockets. There is the Java clients, which is doing this - so I'm pretty sure, that Java...
4
by: google | last post by:
Dear newsgroup, I give up, I must be overseeing something terribly trivial, but I can't get a simple (Java) applet to react to incoming (python) SocketServer messages. Without boring you with...
4
by: yaron | last post by:
Hi, I have a problem when sending data over TCP socket from c# client to java server. the connection established ok, but i can't send data from c# client to java server. it's work ok with...
12
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
0
by: sivasankarmathuraju | last post by:
Hi! I am using: Java 2 SDK 1.4.0 Standard Edition on Windows XP I have one java client application and one gateway that is in C language runing on the same machine. The server creates a...
3
by: akmkat | last post by:
Hi all, I am in a great problem. I am trying to implement a multithreaded server using java, first look at the code... /*------- Main Server (server.java)--------------*/ import java.io.* ;...
5
by: PatlaDJ | last post by:
Java SAX parser, please need a clue how to get the raw XML code of the currently parsing event... needed for logging, debugging purposes. Here's and example, letting me clarify exactly what i...
3
by: TsanChung | last post by:
I want to make a java TCP socket client to communicate with a TCP server socket on linux. Are there some sample C unix server and java client socket programs available? The Richard Stevens'...
2
by: rayoflight | last post by:
This is how my test program works. Server will encrypt some text and sends it over to the client. The client will then decrypts it. However I have some problem decrypting it. When I play...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.