473,508 Members | 4,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asynchat question

I am trying to write both a server and a client using asynchat.
For both, I have created a common subclass to collect the incoming data:

class SingleServer(asynchat.async_chat):
def __init__(self,*args):
asynchat.async_chat.__init__(self,*args)
self.set_terminator(BLOCKEND)
self.data=[]
def collect_incoming_data(self,data):
self.data.append(data)
def found_terminator(self):
self.processData(''.join(self.data))
self.data=[]

The server works well, it waits for a connection and sends a response.

class SecondaryServer(SingleServer):
def processData(self,data):
response='??'
peer=self.getpeername()
print now(),'from %s received %s' % (peer,repr(data))
if data == 'quit':
if peer[0]=='127.0.0.1':
response='OK'
dispatcher.close()
else:
response='KO'
response=response+' '+data
print now(),'to %s responding %s' % (peer,repr(response))
self.push(response+BLOCKEND)

However, I am having trouble with the client, who is supposed to send a
question and get an answer in return:

class Server(SingleServer):
def __init__(self,message,*args):
SingleServer.__init__(self,*args)
print now(),'connecting to EB on %s:%s' % (EBHost,EBPort)
self.create_socket(socket.AF_INET,socket.SOCK_STRE AM)
self.connect((EBHost,EBPort))
def handle_connect(self):
print now(),'sending %s' % repr(message)
self.push(message+BLOCKEND)
def processData(self,data):
print now(),'received "%s"' % repr(response)
self.close() # XXX is socket closed by base class?

Server(message)

The client connects and send his question. The server answers, but the
client never receives an answer. On the server side, I receive the
following message:

error: uncaptured python exception, closing channel
__main__.SecondaryServer connected 127.0.0.1:3432 at 0x7fc968>
(socket.error:(10053, 'Software caused connection abort')
C:\Python23\lib\asynchat.py|handle_read|88] [C:\Python23\lib\asyn
core.py|recv|353])

Can anyone explain why?

--
Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64')
Visit my Homepage at http://www.homepages.lu/pu/

Jul 18 '05 #1
1 2164
Sorry, my mistake.
The behaviour is actually that for the client, handle_connect() is never
called, so the message is never send.

Why?

--
Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64')
Visit my Homepage at http://www.homepages.lu/pu/

Jul 18 '05 #2

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

Similar topics

0
2690
by: Michael Welsh | last post by:
In order to learn sockets in Python I am trying to write a simple group chat server and client. I need a little nudge, please. My question contains some GUI but only as decoration. The root...
4
3003
by: Joshua Moore-Oliva | last post by:
Ok.. so here is my situation. I have an application that I would love to be able to use asynchat with for it's handle_close, found_terminator etc abstraction on. However, I must use a separate...
16
3246
by: Rob Snyder | last post by:
Greetings - I've embarked on a small learning project, trying to get a better grasp of the asyncore and asynchat modules. The project involves building a simple instant messenger application for...
2
1477
by: Andreas R. | last post by:
Hello, I'm using Python's asynchat for networking. If I invoke the send() method of the asynchat module, only a single send operation is possible at any given time. If I call it more than once,...
1
1577
by: Andreas R. | last post by:
Hello, I'm using Python's asynchat module for network support in a Python-based game, and I run into two problems, both of which occur at random times. Most of the time, the network sending and...
8
2590
by: Andreas R. | last post by:
Hi again, I'm using Python's asynchat module for networking. When calling the sendall() method of asynchat, I sometimes get the error message "the operation could not complete without...
1
1241
by: Martin Maney | last post by:
Simple asyncore application where I wanted to use an explicit map (1) rather than the automagic default. Worked fine until I tried to use asynchat to handle an interactive status and control...
5
2449
by: ludvig.ericson | last post by:
Hello, My question concerns asynchat in particular. With the following half- pseudo code in mind: class Example(asynchat.async_chat): def readable(self): if foo:...
0
1123
by: davy zhang | last post by:
Python3.0rc1 windowsxp in the lib\asynchat.py def handle_write (self): self.initiate_send() def push (self, data): sabs = self.ac_out_buffer_size if len(data) sabs:
0
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.