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

client derived from async_chat

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/

Jul 18 '05 #1
4 3043
Erik Max Francis wrote:
I tried to run your sample but you didn't include enough material for me
to run it as a standalone application. When I tried to stub out the
additional material you didn't include, I got connection refused errors,
presumably because the server wasn't running at the point your clients
tried to connect.


Look at the following code:

sock=socket.socket(socket.AF_INET,socket.SOCK_STRE AM)
#sock.setblocking(0)
print 'connect rc=',sock.connect_ex((EBHost,EBPort))
try:
sock.send(message+BLOCKEND)
response=sock.recv(BUFFSIZE)
finally:
sock.close()

If I run it without the 'sock.setblocking(0)', it works fine. If
uncomment that line, I receive the following error:

File "I:\My Programs\sas\sasLA0.py", line 18, in ?
response=sock.recv(BUFFSIZE)
socket.error: (10035, 'The socket operation could not complete without
blocking')

This is exactly what seems to happen with the async_chat class, as in
dispatcher.create_socket the same setblocking(0) is done.

If you just could shed some light on what this error means, I haven't
found any explanation up to now.

Thanks.

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

Jul 18 '05 #2
Patrick Useldinger wrote:
This is exactly what seems to happen with the async_chat class, as in
dispatcher.create_socket the same setblocking(0) is done.

If you just could shed some light on what this error means, I haven't
found any explanation up to now.


It'd doing what you asked it to do. Functions that would block return
an error of EWOULDBLOCK (which is translated into a socket.error
exception in Python) if they would have blocked but you have set the
socket not to block. The error is not an error, it's just the system
telling you, "I would have blocked here, but you told me not to, so I'm
telling you that."

The bigger question is why you're asking the socket to not block when it
appears that you really want it to (since your logic isn't handling the
case when it doesn't).

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Defeat is a school in which truth always grows strong.
\__/ Henry Ward Beecher
Jul 18 '05 #3
Heiko Wundram wrote:
Remember: connecting is also a non-blocking operation, if the socket is
set to non-blocking mode.
I should have read some more about sockets before trying to use
async_chat; I thought I would get by 'just adding a few methods'. Shame
on me ;-)

Anyway, what happened is that 'create_socket()' and 'connect()' were
called to quickly one after the other; as async_chat (asnycore,
actually) sets the socket on creation to non-blocking, my connect failed.

I solved the problem by adding a method 'connect()' in my derived class
which looks like this:

def connect(self,*args):
timeOut=self.gettimeout()
self.settimeout(None)
SingleServer.connect(self,*args)
self.settimeout(timeOut)

This did the trick for my chat client.
I dunno why async_chat doesn't work with this on Windows (on *nix, this
is exactly what it does), but I guess it has something to do with
decoding the error codes, as a *nix-socket would return EWOULDBLOCK in
this case, for which it checks, I am certain of that.


I think it works as designed, but it was not designed to open sockets
for clients, only for servers. I could have opened the socket outside
the method, probably, but I really wanted the class to handle all of the
network stuff.

Anyway, it works fine now.

Thanks for your explanation.

-Patrick

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

Jul 18 '05 #4
Erik Max Francis wrote:
The bigger question is why you're asking the socket to not block when it
appears that you really want it to (since your logic isn't handling the
case when it doesn't).


See my answer to Heiko; it's the class asyncore which handles the
(non-)blocking staff, and I relied on that. Now that I've overridden the
connect() method for my client, it works fine.

Thanks for your help.

-Patrick

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

Jul 18 '05 #5

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

Similar topics

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...
3
by: Gary Varga | last post by:
In the file WebUIValidation.js, when a postback that doesn't fail the validation has a javascript error saying summary is undefined in the ValidationSummaryOnSubmit function....
0
by: H. Scott Buckwalter | last post by:
ASP.NET: I want to control the color of the text for a check box control in JavaScript on the client. I am able to do this by surrounding the check box in a SPAN tag. I then color the span and...
7
by: jtfaulk | last post by:
I need to encode some information on the server side using ASP.NET with C#; sending via HTTP to a client side application, that needs to be decoded in an MFC C++ application. I'm not sure if I...
3
by: kkao77 | last post by:
I am trying to use schema to validate the data that user sent to my service. How do I achieve that using schema? Do I give schema to the client? or do I write my own schema validation inside web...
3
by: TheSteph | last post by:
Hi, I've made a CustomPanel derived from the Panel class. How can I set my own size of the "client area" of that CustomPanel ? ("client area" = Size of the rectangle in which one can drop...
2
by: reckless2k | last post by:
Client side; knows nothing of Derived: class Base { ... virtual void do_something() } #include "Base.h" void main() {
3
by: Harry_Crow | last post by:
I wanted to change the Non client area height. This was not possible in the existing Form TitleBar. So I set the FormBorderStyle= None and I calculated and introduced the Non Client area myself. So...
5
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
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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...

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.