[Tutor] TSR in windows
Patrick Kirk
patrick@kirks.net
Thu Jun 19 07:22:01 2003
This is a multi-part message in MIME format.
--------------070803050909010704010509
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hi all,
I'm writing a little application that will log all contact received on
port 6346. It works a treat except...it leaves a console window open.
Right now I want to learn how to start it in the background and then I
will find a way to give it a System Tray icon.
How do I do this in Python.
The code is attached - its a learning exercise so please excuse if it
appears lame.
--
Best regards,
Patrick Kirk
Mobile: 07876 560 646
--------------070803050909010704010509
Content-Type: text/plain;
name="server.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="server.txt"
#! /usr/bin/env python
from re import * # get regex stuff
from socket import * # get socket stuff
myHost = '' # localhost
myPort = 6346 # free port
# Create listener and process input
def createSocket():
sockobj = socket(AF_INET, SOCK_STREAM) # makes socket object
sockobj.bind((myHost, myPort)) # binds it to server and port
sockobj.listen(50) # listen allowing 50 connections
while 1: # listen 'til process killed
connection, address = sockobj.accept() # waiting for connection
print 'Server connected by ', address # connection is a new socket
data = connection.recv(1024) # read next line on client socket
handshake0 = 'GNUTELLA CONNECT'
handshakeRequest = data.find(handshake0)
request = 'GET '
fileRequest = data.find(request)
if fileRequest == 0:
connection.close() # Rude but how does one say NO?
elif handshakeRequest > 0:
connection.send('GNUTELLA/0.6 200 OK\r\n' ) # lets see what reply we get
if not data: break # send reply line to client
print data
connection.close()
else:
print data
connection.close()
createSocket()
--------------070803050909010704010509--