listening socket

Discussion in 'Python' started by cerr, Sep 8, 2010.

  1. cerr

    cerr Guest

    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:
    cerr, Sep 8, 2010
    #1
    1. Advertising

  2. On Wed, Sep 8, 2010 at 12:59 PM, cerr <> wrote:
    > 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.
    Benjamin Kaplan, Sep 8, 2010
    #2
    1. Advertising

  3. cerr

    cerr Guest

    On Sep 8, 10:06 am, Benjamin Kaplan <> wrote:
    > On Wed, Sep 8, 2010 at 12:59 PM, cerr <> wrote:
    > > 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.


    hoops right... heh, thanks... :$ clearly doing too many things at the
    same time...
    cerr, Sep 8, 2010
    #3
  4. On 2010-09-08, Benjamin Kaplan <> wrote:
    > On Wed, Sep 8, 2010 at 12:59 PM, cerr <> 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??? :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_]

    --
    Grant Edwards grant.b.edwards Yow! I feel partially
    at hydrogenated!
    gmail.com
    Grant Edwards, Sep 8, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian von Essen

    Listening socket not seen outside of localhost

    Christian von Essen, Jun 21, 2004, in forum: Python
    Replies:
    2
    Views:
    413
    Christian von Essen
    Jun 21, 2004
  2. pwilkins
    Replies:
    7
    Views:
    437
    Grant Edwards
    Jun 25, 2005
  3. Giovanni Tumiati
    Replies:
    2
    Views:
    330
    Grant Edwards
    Jun 25, 2005
  4. Jp Calderone
    Replies:
    1
    Views:
    338
    Grant Edwards
    Jun 25, 2005
  5. Jp Calderone
    Replies:
    2
    Views:
    382
    Grant Edwards
    Jun 25, 2005
Loading...

Share This Page