classification
Title: A socket example code shown in doc doesn't work on FreeBSD
Type: Stage:
Components: Documentation Versions: Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: example code does not work
View: 2742
Assigned To: georg.brandl Nosy List: georg.brandl, giampaolo.rodola
Priority: normal Keywords:

Created on 2008-05-04 21:51 by giampaolo.rodola, last changed 2008-05-11 07:04 by georg.brandl. This issue is now closed.

Messages (2)
msg66244 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2008-05-04 21:51
This is the result from executing the second IPv4/IPv6 server example
shown in socket module documentation on a FreeBSD-7 system.
http://docs.python.org/dev/library/socket.html#example


dhcppc1# cat server.py
# Echo server program
import socket
import sys

HOST = ''                 # Symbolic name meaning the local host
PORT = 50007              # Arbitrary non-privileged port
s = None
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,
socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
    af, socktype, proto, canonname, sa = res
    try:
     s = socket.socket(af, socktype, proto)
    except socket.error, msg:
     s = None
     continue
    try:
     s.bind(sa)
     s.listen(1)
    except socket.error, msg:
     s.close()
     s = None
     continue
    break
if s is None:
    print 'could not open socket'
    sys.exit(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
    data = conn.recv(1024)
    if not data: break
    conn.send(data)
conn.close()

dhcppc1#
dhcppc1# uname -a
FreeBSD dhcppc1# 7.0-RC1 FreeBSD 7.0-RC1 #0 Mon Dec 24 12:18:24 UTC 2007
root@logan.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC   o386
dhcppc1#
dhcppc1# python2.5 server.py
Traceback (most recent call last):
  File "server.py", line 8 in <module>
     for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,
socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
socket.gaierror: (8, 'hostname nor servname provided, or not known')
dhcppc1#
msg66605 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-11 07:04
Duplicate of #2742.
History
Date User Action Args
2008-05-11 07:04:36georg.brandlsetstatus: open -> closed
resolution: duplicate
superseder: example code does not work
messages: + msg66605
2008-05-04 21:51:51giampaolo.rodolacreate