CGI

ID #119

I can't get the python socket module to work?

Applies to: Grid System

The python socket module is installed and works. Here is an example of how to use the socket module under Python 2.1

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('modwest.com', 50007))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
data = conn.recv(1024)
if not data: break
conn.send(data)
conn.close()

You can run this script on the command line like so:

python2.1 socket.py

Or, if you add the line

#!/usr/bin/python2.1

as the first line of the script, and it is executable by you

chmod 750 socket.py

then you can run it from the command line like so:

./socket.py

or as a CGI script (assuming it is in your /htdocs/www/cgi-bin directory)

http://yourdomain/cgi-bin/socket.py

Last update: 2010-09-29 16:59
Author: FAQ Admin
Revision: 1.2

Digg it! Share on Facebook Print this record Send FAQ to a friend Show this as PDF file
Please rate this FAQ:

Average rating: 0 (0 Votes)

completely useless 1 2 3 4 5 most valuable

You can comment this FAQ