listening socket

C

cerr

Hi,

I'm trying to create a listening socket connection on port 1514.
I tried to follow the documentation at:
http://docs.python.org/release/2.5.2/lib/socket-example.html
and came up with following lines:
import socket

host = '' # Symbolic name meaning all available
interfaces
port = 1514 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
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()
but that is not working, i'm getting this:
import: unable to open X server `' @ error/import.c/ImportImageCommand/
362.
../sockettest.py: line 4: host: command not found
../sockettest.py: line 5: port: command not found
../sockettest.py: line 6: syntax error near unexpected token `('
../sockettest.py: line 6: `s = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)'

now why would it try to open an x server??? :eek:
 
B

Benjamin Kaplan

Hi,

I'm trying to create a listening socket connection on port 1514.
I tried to follow the documentation at:
http://docs.python.org/release/2.5.2/lib/socket-example.html
and came up with following lines:
import socket

host = ''                 # Symbolic name meaning all available
interfaces
port = 1514               # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
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()
but that is not working, i'm getting this:
import: unable to open X server `' @ error/import.c/ImportImageCommand/
362.
./sockettest.py: line 4: host: command not found
./sockettest.py: line 5: port: command not found
./sockettest.py: line 6: syntax error near unexpected token `('
./sockettest.py: line 6: `s = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)'

now why would it try to open an x server??? :eek:
--

Because it's not executing it as a Python program. It's trying to
execute it as a shell script. If you want to run a script as a Python
program, either call the interpreter directly
python sockettest.py

or include a Shebang line as the first line of the file that tells the
computer what interpreter to use
#!/usr/bin/env python

The file extension itself is meaningless to a Unix shell- it's just a
part of the file name.
 
C

cerr

Because it's not executing it as a Python program. It's trying to
execute it as a shell script. If you want to run a script as a Python
program, either call the interpreter directly
python sockettest.py

or include a Shebang line as the first line of the file that tells the
computer what interpreter to use
#!/usr/bin/env python

The file extension itself is meaningless to a Unix shell- it's just a
part of the file name.

hoops right... heh, thanks... :$ clearly doing too many things at the
same time...
 
G

Grant Edwards

but that is not working, i'm getting this:
import: unable to open X server `' @ error/import.c/ImportImageCommand/ [...]
now why would it try to open an x server??? :eek:

Because it's not executing it as a Python program. It's trying to
execute it as a shell script.

What's even more fun is if you do have an X server, and the shell is
able to run the import program, and it does open the X server, and so
on...

[Not that things like that ever happen to _me_]
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top