473,326 Members | 2,111 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,326 software developers and data experts.

Annoying Socket Problem

I'm hoping this is something simple, and someone can point me in the
right direction here. I have a class based on SocketServer
(ThreadingTCPServer), and I've used makefile on the socket so I use the
"for in " routine. My client sends it a small amount of data. However,
both programs appear to hang once the data has been sent, obviously
something to do with flushing.

I'd appreciate any pointers.

Regards

J

Server Class:

class _DBSocketHandler( SocketServer.BaseRequestHandler ):

xmlStart = re.compile( "XML-START" )
xmlEnd = re.compile( "XML-END" )

def handle( self ):
print "Accepted Connection From", self.client_address
socketIn = self.request.makefile( 'r' )
socketOut = self.request.makefile( 'wb' )
remoteDoc = None
for dataIn in socketIn:
if self.xmlEnd.match( dataIn ):
remoteDoc.close()
break
if self.xmlStart.match( dataIn ):
print "Receiving XML"
remoteDoc = StringIO()
continue

if remoteDoc is not None:
remoteDoc.write( dataIn )

socketOut.write( "Got Yer XML File, Thanks" )

Client Code:

def connect( self ):
self.socketCon.connect( ( self.dbServer, self.dbPort ) )
testFile = StringIO.StringIO( testXML )
self.socketCon.send( "XML-START" )
for xmlSQL in testFile:
self.socketCon.send( xmlSQL )
testFile.close()
self.socketCon.send( "XML-END" )
self.socketCon.send( "" )
time.sleep(10)
while True:
dataRec = self.socketCon.recv( 8192 )
if not dataRec: break
self.socketCon.close()
Jul 18 '05 #1
3 1677
John Abel wrote:
I'm hoping this is something simple, and someone can point me in the
right direction here. I have a class based on SocketServer
(ThreadingTCPServer), and I've used makefile on the socket so I use the
"for in " routine. My client sends it a small amount of data. However,
both programs appear to hang once the data has been sent, obviously
something to do with flushing.


http://www.amk.ca/python/howto/socke...00000000000000

--Irmen
Jul 18 '05 #2
Read/tried that before posting. Even with a flush, everything hangs
until I kill the client.

Irmen de Jong wrote:
John Abel wrote:
I'm hoping this is something simple, and someone can point me in the
right direction here. I have a class based on SocketServer
(ThreadingTCPServer), and I've used makefile on the socket so I use
the "for in " routine. My client sends it a small amount of data.
However, both programs appear to hang once the data has been sent,
obviously something to do with flushing.

http://www.amk.ca/python/howto/socke...00000000000000
--Irmen

--
*John Abel
Senior Unix Administrator*
PA News Limited
www.pa.press.net <http://www.pa.press.net>
E-Mail address: jo*******@pa.press.net <mailto:jo*******@pa.press.net>
Telephone Number : 01430 455553
Fax Number : 0870 1240192
Mobile Number : 07971 611356
The Bishop's Manor, Market Place, Howden, DN14 7BL
PA News Limited, 292 Vauxhall Bridge Road, London SW1V 1AE. Registered
in England No. 3891053.
Jul 18 '05 #3
Never mind, sorted now.

On 18 Feb 2005, at 15:10, John Abel wrote:
Read/tried that before posting. Even with a flush, everything hangs
until I kill the client.

Irmen de Jong wrote:
John Abel wrote:
I'm hoping this is something simple, and someone can point me in the
right direction here. I have a class based on SocketServer
(ThreadingTCPServer), and I've used makefile on the socket so I use
the "for in " routine. My client sends it a small amount of data.
However, both programs appear to hang once the data has been sent,
obviously something to do with flushing.

http://www.amk.ca/python/howto/sockets/
sockets.html#SECTION000400000000000000000

--Irmen

--
*John Abel
Senior Unix Administrator*
PA News Limited
www.pa.press.net <http://www.pa.press.net>
E-Mail address: jo*******@pa.press.net <mailto:jo*******@pa.press.net>
Telephone Number : 01430 455553
Fax Number : 0870 1240192
Mobile Number : 07971 611356
The Bishop's Manor, Market Place, Howden, DN14 7BL
PA News Limited, 292 Vauxhall Bridge Road, London SW1V 1AE. Registered
in England No. 3891053.
--
http://mail.python.org/mailman/listinfo/python-list


Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bryan Olson | last post by:
Here's the problem: Suppose we use: import socket f = some_socket.makefile() Then: f.read() is efficient, but verbose, and incorrect (or at least does not play will with others);
4
by: faktujaa | last post by:
Hi, I am having some problem with callback used in socket implementation. private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref Socket rsocClient) { try { // Create remote end...
4
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
4
by: Sa¹o Zagoranski | last post by:
Hi! I'm writing a simple 3D First person shooter game. It is a multiplayer game, where all the players connect to one server.
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
6
by: ahlongxp | last post by:
socket.makefile() may lose data when "connection reset by peer". and socket.recv() will never lose the data. change the "1" to "0" in the client code to see the difference. confirmed on both...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
16
by: =?iso-8859-1?q?|-|e|=5F|=5F_B0=DD?= | last post by:
hi all! I got a problem. I declared a SOCKET var in my C program but when i compiled the program it displayed like *--------------------------------------------------------------* *'SOCKET':...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.