#!/usr/bin/python #client from socket import * HOST = ' 127.0.0.1 ' PORT = 21567 Bufsiz = 1024x768 ADDR = (host,port) tcpclis Ock = socket (af_inet, Sock_stream) tcpclisock.connect (ADDR) recv_s = Tcpclisock.recv (bufsiz) print recv_s try:while True:send_c = Raw_input (' clinet: ') tcpclisock.send (' Client:%s '% (send_c)) recv_s = Tcpclisock. Recv (bufsiz) print recv_s finally:tcpCliSock.close ()
Server:
#!/usr/bin/python from socket import * host = ' PORT = 21567 BUFSIZ = 1024 ADDR = (Host, port) tcpsersock = socket (Af_inet, sock_stream) tcpsersock.bind (ADDR) tcpsersock.listen (1) try: while true: print ' waiting for connection ... ' tcpclisock, addr = tcpsersock.accept () print ' ... Connected from: ', addr tcpclisock.send (' Please have a talk ') try: while True:        RECV_C = TCPCLISOCK.RECV (BUFSIZ) print recv_c send_s = Raw_input (' server: ') tcpclisock.send (' server: %s ' % (send_s)) finally: Tcpclisock.close () finally: tcpsersock.close ()
Python Socket Socket Programming