views:

125

answers:

3

I have written a Python TCP/IP server for internal use, using win32serviceutil/py2exe to create a Windows service.

I installed it on a computer running Windows XP Pro SP3. However, I can't connect to it when it's running as a service. I can confirm that it's binding to the address/port, because I get a conflict when I try to bind to that address/port with another application. Further, I have checked the Windows Firewall settings and have added appropriate exceptions. If I run the server as a simple console application, everything works as expected. However, when I run it as a service, it doesn't work.

I vaguely remember running into this problem before, but for the life of me can't remember any of the details.

Suggestions, anyone?

+1  A: 

Possibly the program may be terminated just after initialization. Please check whether it is continuously listening to the requests.

netstat -an |find /i "listening"

And analyze the command line parsed to the programs. You may use procexp to do that.

Chathuranga Chandrasekara
Here are the relevant entries: TCP server:34300 localhost:1028 TIME_WAIT TCP server:34300 [IP Address Removed]:4471 TIME_WAIT TCP server:34300 [Computer Name Removed]:61001 TIME_WAIT
Out of Hanwell
The program is clearly listening:`TCP 0.0.0.0:34300 0.0.0.0:0 LISTENING 828
Out of Hanwell
A: 

Check to see that the service is running under the Nertwork Service account and not the Local System account. The later doesn't have network access and is the default user to run services under. You can check this by going to the services app under administrative tool in the start menu and looking for your service. If you right-click the service you can go to properties and change the user that it is run under.

Robbie
As I mentioned, it works when I run it interactively. I also tried running the service under the same user, and it didn't work.
Out of Hanwell
+1  A: 

First of all, whenever you implement a Windows service, be sure to add proper logging.

My worker threads were terminating because of the exception, "The socket operation could not complete without blocking."

The solution was to simply call sock.setblocking(1) after accepting the connection.

Out of Hanwell