I'm new to the forum and also to python :D. Anyway I have been enjoying it quite a bit and wanted to start into something a bit more technical. So I though sockets would be a good start. I found a great sight , but the first script I found there seems to have some errors.
Could someone plz look this over and fix it for me? And also its been along time since I tackled programming but isn't there like a system pause or something I can stop scripts at a certain point with. If so can someone help refresh my memory. Thanx alot and diggin this sight.:)
code for server
from socket import * HOST ='localhost' PORT =21567 BUFSIZ =1024 ADDR =(HOST, PORT) serversock = socket(AF_INET, SOCK_STREAM) serversock.bind(ADDR) serversock.listen(2) while 1: print'waiting for connection...' clientsock, addr = serversock.accept() print'Connection made from: ', addr while 1: data =clientsock.recv(BUFSIZ) if not data: break clientsock.send('echoed', data) clientsock.close() serversock.close()
code for client
from socket import * HOST ='localhost' PORT =21567 BUFSIZ =1024 ADDR =(HOST, PORT) tcpCliSock = socket(AF_INET, SOCK_STREAM) tcpCliSock.connect(ADDR) while 1: data =raw_input('> ') if not data: break tcpCliSock.send(data) data = tcpCliSock.rec(1024) if not data: break print data tcpCliSock.close()