nt-services

Frank Immich frankimmich at gmx.de
Thu Jun 7 08:12:16 EDT 2001


Hello there, 
I have a question concerning socket connections running   as NT-Service. I
found the demoscript  in win32/demos/service/ PipeService.py and I think
(hope) I understood most of it. But transferring this example using sockets
instead of named pipes doesn't work. Basically I want to have a little service
running on NT which is waiting for a command from a Unix machine, passing back
stdin , sdterr .... Without the NT-service-thing it is working fine.  
I hope you are good address for win32 questions. I have asked this in the
german newsgroup too, but most of the guys seem to be more experienced in
UNIX/LINUX (thanks for the answers, anyway). Maybe you can give me a  clearer
hint.  Thanks in advance , Ciao Frank 

This is my  little script with a very basic socket:

import sys, os, string 
from socket import * 
import win32serviceutil 
import win32service 
import win32event 
import pywintypes
port = 4127 
BUFSIZE = 1024
class TestPipeService(win32serviceutil.ServiceFramework): 
_svc_name_ = "test" 
_svc_display_name_ = "test" 
def __init__(self, args): 
win32serviceutil.ServiceFramework.__init__(self, args) 
self.hWaitStop = CreateEvent(None, 0, 0, None) 
self.overlapped = pywintypes.OVERLAPPED() 
self.overlapped.hEvent = CreateEvent(None,0,0,None)

#I have to use overlapped I/O, right ?? 

def SvcStop(self): 
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) 
SetEvent(self.hWaitStop)

def SvcDoRun(self): 
s = socket(AF_INET, SOCK_STREAM) 
s.bind(('', port)) 
s.listen(1) 
while 1:

conn, (remotehost_ip, remoteport) = s.accept()
I don't know how to wait for the connection (accept) "event" and how to
process the event ? 
The guys from the german newsgroup told me to use win32file.AcceptEx ??? but
I don't know how... 

myHandels = self.hWaitStop, self.overlapped.hEvent 
stp = win32event.WaitForMultipleObjects(myHandels,0,win32event.INFINITE) 
if stp==win32event.WAIT_OBJECT_0: 
break 
else: 

hostname, aliaslist, ipaddr = gethostbyaddr 
(remotehost_ip) 
data = conn.recv(BUFSIZE) 
if not data: 
break 
data = data + " host:" + hostname 
conn.send(data) 
conn.close()

if __name__=='__main__': 
win32serviceutil.HandleCommandLine(test)



-- 
Machen Sie Ihr Hobby zu Geld bei unserem Partner 1&1!
http://profiseller.de/info/index.php3?ac=OM.PS.PS003K00596T0409a

--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net





More information about the Python-list mailing list