Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Sockets and xml problem

Reply
Thread Tools

Sockets and xml problem

 
 
kaklis@gmail.com
Guest
Posts: n/a
 
      05-28-2010
Hi in the following code

class MyClientHandler(SocketServer.BaseRequestHandler):
def handle(self):
print self.client_address, now( )
time.sleep(5)
while True:
xmltxt = self.request.recv(1024) <--is this ok -
enough?
if not xmltxt: break

doc = minidom.parseString(data)
<--- it also fails for parse(data)
rootNode = doc.documentElement

level = 0

walk(rootNode, outFile, level)
<---just a function to print the xml
self.request.send('Echo=>%s at %s' % (data, now( )))
rootNode = doc.documentElement
level = 0
walk(rootNode, outFile, level)
self.request.send('Echo=>%s at %s' % (data, now( )))
self.request.close( )

# make a threaded server, listen/handle clients forever
myaddr = (myHost, myPort)
server = SocketServer.ThreadingTCPServer(myaddr, MyClientHandler)
server.serve_forever( )


I want to send XML messages from my client. The server sends back the
XML it receives but
the parser exits with error codes.
What am i doing wrong.

Thanks in advance
 
Reply With Quote
 
 
 
 
Stefan Behnel
Guest
Posts: n/a
 
      05-28-2010
http://www.velocityreviews.com/forums/(E-Mail Removed), 28.05.2010 13:50:
> Hi in the following code
>
> class MyClientHandler(SocketServer.BaseRequestHandler):
> def handle(self):
> print self.client_address, now( )
> time.sleep(5)
> while True:
> xmltxt = self.request.recv(1024)<--is this ok -
> enough?


Depends. If your messages are never larger than 1K, this is enough.
Otherwise, you have to collect the data, instead of parsing each chunk
separately.

I suggest using the incremental parser in xml.etree.ElementTree, which
allows you to push more data into the parser as it comes in. When done,
call it's .close() method to retrieve the result.

http://docs.python.org/library/xml.e...uilder-objects


> I want to send XML messages from my client. The server sends back the
> XML it receives but the parser exits with error codes.


You should also rethink your approach one more time. Are you sure that a
raw socket is a good protocol for sending your messages? In many cases, a
proper higher-level transport protocol like HTTP is much better suited. If
you provide more details about what you are trying to do, others may be
able to help you further.

Stefan

 
Reply With Quote
 
 
 
 
kaklis@gmail.com
Guest
Posts: n/a
 
      05-28-2010
On May 28, 3:23*pm, Stefan Behnel <(E-Mail Removed)> wrote:
> (E-Mail Removed), 28.05.2010 13:50:
>
> > Hi in the following code

>
> > class MyClientHandler(SocketServer.BaseRequestHandler):
> > * * *def handle(self):
> > * * * * *print self.client_address, now( )
> > * * * * *time.sleep(5)
> > * * * * *while True:
> > * * * * * * *xmltxt = self.request.recv(1024)<--is this ok -
> > enough?

>
> Depends. If your messages are never larger than 1K, this is enough.
> Otherwise, you have to collect the data, instead of parsing each chunk
> separately.
>
> I suggest using the incremental parser in xml.etree.ElementTree, which
> allows you to push more data into the parser as it comes in. When done,
> call it's .close() method to retrieve the result.
>
> http://docs.python.org/library/xml.e...ml#xmltreebuil...
>
> > I want to send XML messages from my client. The server sends back the
> > XML it receives but the parser exits with error codes.

>
> You should also rethink your approach one more time. Are you sure that a
> raw socket is a good protocol for sending your messages? In many cases, a
> proper higher-level transport protocol like HTTP is much better suited. If
> you provide more details about what you are trying to do, others may be
> able to help you further.
>
> Stefan


Stefan first of all thank you for your response.
I don't want anything fancy. Just a simple server that accepts xml
messages from multple clients in xml,
parses the XML and show it in a console.
Antonis
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xml + sockets in java A K Java 4 03-15-2008 04:01 AM
Problem to insert an XML-element by XSLT-converting from one XML-file into another XML-file jkflens XML 2 05-30-2006 09:41 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Help needed in problem with Threads and sockets. Gonšalo Rodrigues Python 0 12-29-2003 07:39 PM
Problem with blocking portably on sockets and Queue? Tero Saarni Python 2 08-07-2003 04:44 AM



Advertisments