[Tutor] Socket Programming

Joseph Quigley cpu.crazy at gmail.com
Sun Jul 31 05:42:14 CEST 2005


I've got a little problem with my socket program(s):

#Client
import socket
#create an INET, STREAMing socket
s = socket.socket(
    socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 2000))
s.send('hello!'[totalsent:])

#Server
import socket
#create an INET, STREAMing socket
serversocket = socket.socket(
    socket.AF_INET, socket.SOCK_STREAM)
#bind the socket to a public host,
# and a well-known port
serversocket.bind((socket.gethostname(), 2000))
#become a server socket
serversocket.listen(5)

while 1:
        #accept connections from outside
        clientsocket, address = serversocket.accept()
        serversocket.recv()

I have no idea how to get the server to receive and print a message or 
for the client to send the message. Does anyone know of some good python 
networking tutorials designed for newbies? (Not ones on 
www.awaretek.com. They seem to expect you to know some things that I 
don't even know about.)

Thanks,
    Joe Q.



More information about the Tutor mailing list