Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

listening socket

3 views
Skip to first unread message

cerr

unread,
Sep 8, 2010, 12:59:18 PM9/8/10
to
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??? :o

Benjamin Kaplan

unread,
Sep 8, 2010, 1:06:44 PM9/8/10
to pytho...@python.org
> --

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.

cerr

unread,
Sep 8, 2010, 1:11:16 PM9/8/10
to
On Sep 8, 10:06 am, Benjamin Kaplan <benjamin.kap...@case.edu> wrote:

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

Grant Edwards

unread,
Sep 8, 2010, 1:47:38 PM9/8/10
to
On 2010-09-08, Benjamin Kaplan <benjami...@case.edu> wrote:
> On Wed, Sep 8, 2010 at 12:59 PM, cerr <ron.e...@gmail.com> wrote:

>> 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??? :o
>

> 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_]

--
Grant Edwards grant.b.edwards Yow! I feel partially
at hydrogenated!
gmail.com

0 new messages