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

Slow Python and Sockets in windows

I have been making a client-server type of software mainly on Linux and
now I am trying to get it all work also on windows. However, I am having
slight problems running the program in Windows 2000. I have tried Python
2.2.3 and the latest release 2.3.1 (?)

If I have 2 clients and 1 server. The server listening some predefined
port and all the sending (in client and server) is done by creating a
new connection. On the beginning the client "logs on" to the server.
Now, starting the server and first client is ok, but when I try to start
the second client (all on the same machine) it takes 35 seconds to
start!!? And most of the time seems to go on starting python itself (it
does not even reach the first line of __init__), not my program or the
networking stuff. All the data goes through the server.

The connections are TCP and the sending of message is ended by
shutdown(2) and close() both in the server and client end. The server
extends ThreadingMixIn and TCPServer and uses very simple Handler that
extends StreamRequestHandler and overrides the handle method simply
appending the received data into a string and calling a method of the
server with the string as parameter. The server and client use ports >
8000.

Should I close the socket at the Handler end when the sender as closed
the connection?

There were also broken connections ("connection refused") until I
changed the connection to connect_ex and kept trying until it succeeded
(not good, but I made it to see if it helps). The console windows, on
which I run the server and clients, are very slow and the printouts may
take a while before appearing (some speed optimization by MS?) and the
socket operations seem to be slow. I had none of these problems on
Linux.

Am I missing something or what is going on?
Here's the handler:

class ChannelListener(StreamRequestHandler):
def handle(self):
req=""
buffer=self.request.recv(512)
print self.request
while len(buffer)>0:
req+=str(buffer)
buffer=self.request.recv(512)
self.server.processRequest(self.request,req)
return
and the send method of server:

def send(self,container,msg):
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# some lines removed, basically just doing:
connection_data=(ip,port) # ip & port comes from a list
pirunmuuttuja=1
while(pirunmuuttuja!=0):
pirunmuuttuja=s.connect_ex(connection_data)
s.send(msg)
s.shutdown(2)
s.close()

and the send method of the client:

def send(self,msg):
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
pipa=1
while(pipa!=0):
pipa=s.connect_ex(self.server)
s.send(msg)
s.shutdown(2)
s.close()

I'd appreciate any feedback (other than "your code sucks!" ;) ).

Thanks!

--
Rami Saarinen

if you would like to aswer by email, plese do remove the obvious part
from my email address.
Jul 18 '05 #1
1 5785
I don't see the problem in this snippet of code.
However, the connect calls should succeed without the need to
continually retry.
The 35 second startup sounds like something is waiting for a timeout
to complete.
The recv() calls are blocking calls by default.
Could you be blocked in a recv() call.
I can't see if you are using threads to handle each client
communication.

You have also ommitted how you are accepting connections. Perhaps the
server may be busy and not ready to accept connections.

Have you looked into using asyncore and asynchat. These modules make
TCP/IP communication very easy.
Jul 18 '05 #2

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

Similar topics

13
by: Grant Edwards | last post by:
A few months back I wrote a sort of a strip-chart recorder program that talks DeviceNet to a measurement widget and plots the received data in more-or-less real time using the Gnuplot module. It...
5
by: ias0nas | last post by:
Is it possible to have low level netwoking with python under Windows? Like raw sockets? Is it possible to send a single packet using python under windows? Thank you
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 391 open ( +7) / 3028 closed (+12) / 3419 total (+19) Bugs : 906 open ( -3) / 5519 closed (+19) / 6425 total (+16) RFE : 207 open...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 393 open (+15) / 3315 closed (+17) / 3708 total (+32) Bugs : 908 open (+22) / 5975 closed (+49) / 6883 total (+71) RFE : 223 open...
1
by: Jim Langston | last post by:
Windows. Situation: Using a Python program called OpenRPG. I have a program that displays form data (a character sheet) in C++. I am able in the C++ program to build a string and copy it into the...
1
by: inhahe | last post by:
i'm trying to make a .dll that will let me use WSAPoll, which is a windows sockets function, to mimic select.poll on a windows box. i cbb learning python extensions, so i'm just going to use...
7
by: Brendon Costa | last post by:
Hi all, I have a small python project i am working on. Basically i always have two threads. A "Read" thread that sits in a loop reading a line at a time from some input (Usually stdin) and then...
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: 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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.