Windows NT Service and Sockets

O

Olaf Meding

How can I used WaitForMultipleObjects() with sockets? The code (shown
below) respresents a very simple echo server using sockets. I need
WaitForMultipleObjects() so I can wait for both a new connection and
the stop command from the service manager.

Your help is greatly appreciated. Thanks.

Olaf


def SvcDoRun(self):
sock = socket(AF_INET, SOCK_STREAM)
sock.bind(('localhost', 53574))
sock.listen(1)

connection, addr = sock.accept()
data = connection.recv(1024)
connection.send(data)
connection.close()

# We do nothing other than wait to be stopped!
win32event.WaitForSingleObject(self.hWaitStop,
win32event.INFINITE)
 
T

Thomas Heller

How can I used WaitForMultipleObjects() with sockets? The code (shown
below) respresents a very simple echo server using sockets. I need
WaitForMultipleObjects() so I can wait for both a new connection and
the stop command from the service manager.

Your help is greatly appreciated. Thanks.

Look into win32file.WSAEventSelect, it allows to associate an event
object with FD_XXX network events.

Thomas
 
G

Gandalf

How can I used WaitForMultipleObjects() with sockets? The code (shown
below) respresents a very simple echo server using sockets. I need
WaitForMultipleObjects() so I can wait for both a new connection and
the stop command from the service manager.

Your help is greatly appreciated. Thanks.

Olaf


def SvcDoRun(self):
sock = socket(AF_INET, SOCK_STREAM)
sock.bind(('localhost', 53574))
sock.listen(1)

connection, addr = sock.accept()
data = connection.recv(1024)
connection.send(data)
connection.close()

# We do nothing other than wait to be stopped!
win32event.WaitForSingleObject(self.hWaitStop,
win32event.INFINITE)
It is common to use a different thread for your main program and other
thread(s) to handle service
manager commands. Hint: you can use select.select on the server socket
object to wait for
an incoming connection for a certain amount of time.

Best,

Laci
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top