Problem with socket

DelPiccolo Ivano ivano.delpiccolo at degroof.be
Wed Feb 13 09:54:25 EST 2002


I tried to impement a very simple client-server application.
Hre's the output from the server part :

Traceback (most recent call last):
  File "C:\Python22\Pythonwin\pywin\framework\scriptutils.py", line 301, in
RunScript
    exec codeObject in __main__.__dict__
  File "D:\server.py", line 10, in ?
    data = conn.recv(1024)
  File "<string>", line 1, in recv
  File "C:\Python22\lib\socket.py", line 159, in __getattr__
    raise error(9, 'Bad file descriptor')
error: (9, 'Bad file descriptor')


Here's my server.py :
import socket
host = ''
port = 50007
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(10)
    if not data : break
    conn.send(data)
    conn.close()

Here's my client.py :

import socket
host = '172.16.4.8'
port = 50007
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect((host,port))
s.send("123456789")
data = s.recv(10)
s.close()
print `data`


WHERE IS THE ERROR ?????????????
I don't have any error on the client side, and the client recive correctly
the data.

Thanks in advance





More information about the Python-list mailing list