python - socket error in chat application An error operation was attempted on something that is not a socket -
i trying create simple chat application on python . have created client.py , server.py taking reference site
the server runs fine while running of client code gives error as
to resolve issue have reset winsock , tried reinstall tcp/ip this site
how resolve issue client.py
import socket, select, string, sys def prompt() : sys.stdout.write('<you> ') sys.stdout.flush() #main function if __name__ == "__main__": if(len(sys.argv) < 3) : print 'usage : python telnet.py hostname port' sys.exit() host = sys.argv[1] port = int(sys.argv[2]) s = socket.socket(socket.af_inet, socket.sock_stream) s.settimeout(2) # connect remote host try : s.connect((host, port)) except : print 'unable connect' sys.exit() print 'connected remote host. start sending messages' prompt() while 1: socket_list = [sys.stdin, s] # list sockets readable read_sockets, write_sockets, error_sockets = select.select(socket_list , [], []) sock in read_sockets: #incoming message remote server if sock == s: data = sock.recv(4096) if not data : print '\ndisconnected chat server' sys.exit() else : #print data sys.stdout.write(data) prompt() #user entered message else : msg = sys.stdin.readline() s.send(msg) prompt()
Comments
Post a Comment