trying sockets

Mark Berry pengo243 at hotmail.com
Tue Oct 2 10:03:20 EDT 2001


Without trying to write the code for you, basically your binding a
local socket and trying to serve connections, not just connect to a
remote socket. ;-)

they have pretty simple examples for doing this in the OReilly python
books, or probably any for that matter that covers sockets.

Good luck



On 2 Oct 2001 13:07:16 GMT, Uwe Schmitt <uwe at rocksport.de> wrote:

>Hi,
>
>i'm just playing with the socket module: i'd like to send
>a "GET/HTTP" request to a webserver and record the answer
>of the server. so i wrote
>
>   from socket import *
>
>   snd=socket(AF_INET,SOCK_STREAM)
>   snd.connect(("www.num.uni-sb.de",80))
>   print snd.getsockname()
>
>   lstn=socket(AF_INET,SOCK_STREAM)
>   lstn.bind(snd.getsockname())
>
>   snd.send("GET / HTTP/1.0 ")
>   lsten.listen(1)
>   conn,addr=lstn.accept()
>   print conn.recv(1024)
> 
>   lstn.close()
>   snd.close()
>
>but i get the following output:
>
>   ('134.96.31.42', 1662)
>   Traceback (most recent call last):
>      File "client.py", line 8, in ?
>        lsten.bind(snd.getsockname())
>   socket.error: (98, 'Address already in use')
>
>so: what did i do wrong ???
>
>yours, uwe.
> 
>
>
>-- 
>Uwe.Schmitt at num.uni-sb.de      Universität des Saarlandes
>phone: +49 (0)681/302-2468     Geb. 36.1, Zi. 4.17, PF 151150
>                               D-66041  Saarbrücken
>http://www.rocksport.de        http://www.rocksport.de/first_ride.mp3
>




More information about the Python-list mailing list