473,385 Members | 1,351 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,385 software developers and data experts.

problem with async_chat

rix
Hi there,
I am writing an application that requires a client-server interaction.
Looking up on the internet and working on it I came up with something
like this:
a class ADFSServer that takes inbound connections and dispatches them
to ADFSReceiver.
The connection is always initialized by ADFSSender.
here is the code:

import asynchat
import asyncore
import socket
import string

class ADFSServer (asyncore.dispatcher):

def __init__ (self, port):
asyncore.dispatcher.__init__ (self)
self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
here = ('', port)
self.bind (here)
self.listen (1)

def handle_accept (self):
print ("Server is accepting connection")
ADFSReceiver (self, self.accept())

class ADFSReceiver (asynchat.async_chat):

channel_counter = 0

def __init__ (self, server, (conn, addr)):
asynchat.async_chat.__init__ (self, conn)
self.set_terminator ('\n')
self.server = server
self.id = self.channel_counter
self.channel_counter = self.channel_counter + 1
self.buffer = ''
print ("Receiver created")

def collect_incoming_data (self, data):
self.buffer.append(data)
print ("collecting data")

def found_terminator (self):
data = self.buffer
self.buffer = ''
print '[Received Message]\n %s' % (self.id, repr(data))
self.close()
return data

def handle_close (self):
print 'Closing receiver'
self.close()

class ADFSSender (asynchat.async_chat):

def __init__ (self, data, address):
print "creating sender"
asynchat.async_chat.__init__ (self)
#self.set_terminator ("\n")
self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
self.connect (address)
self.push(data)
self.push ("\n")

if __name__ == '__main__':
work1 = ADFSServer (1234)
asyncore.loop()
I start the server on a shell, and from another shell I launch the
ADFSSender.
The problem is that if I use the push() function the code doesn't work.
If I use the send() it works.
As I am using the async_chat class, I would like to use the push()
method, so I was wondering what was the problem with my code...

thanks,
rix

Nov 3 '05 #1
0 1218

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

Similar topics

4
by: Patrick Useldinger | last post by:
Has anybody got such an example? My server works fine, but my client does not :-( -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/
0
by: F.G.Testa | last post by:
Hi folks! How to receive a notification when a async_client is closed? class AcmePopupChannel(asynchat.async_chat): .... def handle_close(self): print 'Closed channel' def...
117
by: Peter Olcott | last post by:
www.halting-problem.com
3
by: Jos | last post by:
Hello. I'm using the asyncore and _chat modules to create a network server. I also have, running in a separate thread(s), a "producer" which needs to "push" data onto the network connection(s)....
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: davy zhang | last post by:
I wrote this server to handle incoming messages in a process using multiprocessing named "handler", and sending message in a Thread named "sender", 'cause I think the async_chat object can not...
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.