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

win32 service and sockets

Hi,

I created a win32 service for XPPro called N4010ATestService.py (see below).
The service runs as a particular user with administrative rights. It starts a
thread that creates a simple socket server (N4010ASocketServer.py -- also
below) that just waits for 20 character string. When I run the socket server
by itself the test client can connect to the server and send a 20 character
string just fine. When I run the service, the server will bind to the port
but the client cannot connect. I verified the server was listening on the
given port using netstat -an. The client eventually times out. Why isn't the
server accepting connections when run in a service?

Thanks,
Tom

N4010ATestService.py:
---------------------
import win32serviceutil
import win32service
import win32event
import N4010ASocketServer
from thread import start_new_thread

class N4010ATestService(win32serviceutil.ServiceFramewor k):
_svc_name_ = "N4010ATestService"
_svc_display_name_ = "N4010A Test Service"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)

def SvcDoRun(self):
start_new_thread(N4010ASocketServer.main, ())
N4010ASocketServer.waitfor()

def SvcStop(self):
# Before we do anything, tell the SCM we are starting the stop process.
self.ReportServiceStatus(win32service.SERVICE_STOP _PENDING)
N4010ASocketServer.stop()

if __name__ == '__main__':
win32serviceutil.HandleCommandLine(N4010ATestServi ce)
N4010ASocketServer.py:
----------------------
from socket import socket
from select import select
from time import sleep
import win32evtlogutil

applicationName = 'N4010ASocketServer'
messageDll = 'C:\Python24\Lib\site-packages\win32\pythonservice.exe'
running = True
stopped = False

def registerWithEventViewer():
win32evtlogutil.AddSourceToRegistry(applicationNam e, messageDll)

def stop():
import servicemanager
servicemanager.LogInfoMsg('stopping')
global running
running = False

def waitfor():
while not stopped:
sleep(0.5)

def main():
import servicemanager
registerWithEventViewer()
servicemanager.LogInfoMsg('creating socket')
sock = socket()
servicemanager.LogInfoMsg('binding to port 48777')
sock.bind(('0.0.0.0', 48777))
servicemanager.LogInfoMsg('listening')
sock.listen(5)
while running:
servicemanager.LogInfoMsg('Waiting for connection.')
readyRead, readyWrite, inerror = select([sock], [], [], 0)
while (not readyRead) and running:
sleep(0.5)
readyRead, readyWrite, inerror = select([sock], [], [], 0)
if running:
conn, address = sock.accept()
msg = conn.recv(20)
servicemanager.LogInfoMsg('Recvd msg: %s' % msg)
conn.close()
global stopped
stopped = True
Jul 18 '05 #1
0 1472

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

Similar topics

3
by: BizzyTalking | last post by:
Would any kindly tell me if its possible to communicate between a service and a form application. For example, retrieve information from the service, like current activity or progress of its...
0
by: whizpop | last post by:
Hi, First of all, thanks for a great starter kit, now If I could just get it to work (fully). I am trying to compile and run the solution/services all on a local dev box. I am able to...
11
by: kshetgar | last post by:
I am experiencing a wierd problem... I have a C#.Net application Server which uses Sockets. It listens on port 11000. and it runs as a Windows Service. If I run it as a consple Application,...
48
by: Daniele C. | last post by:
As soon as my sourceforge.net project gets approved, I am going to build a ncurses port to win32 bindable to sockets, e.g. allowing VT100/ANSI terminals and the creation of simple terminal servers...
4
by: rob | last post by:
Is there a relatively easy way to send text from a Win32 process to a ..NET process, preferably in VC++ for the Win32 side and C# for .NET.
0
by: ArkJ | last post by:
Hello. I have a little problem. I created a little Service which uses SIP, all works rather well, but when I want to shut it down in the Services panel, it looks as if it's shut down, but in fact...
7
by: GD | last post by:
Hi, I am trying to call a webservice from a windows service application. It works only if I launch the windows service app from VS.Net 2005 (Worked around from Main()) or from a winform test...
1
by: mdhaman | last post by:
hi, I have a windows service written in VB.Net and framework 2.0. It is a multithread service and it is using threadpool to manage threads. Recently I have started getting...
2
by: =?Utf-8?B?U2Vhbk1hYw==?= | last post by:
I am familiar with how to use winsock in vb6 to create a network app. I'm trying to find a way to take the current vb6 app and create a windows service using system.net.sockets. How do you create...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.