Unable to assign IP addresses to server/client in Python Socket Programming -
i'm working on socket level chat assignment requires me have server stores usernames , ip addr&port numbers , give out client needs enable chat between them. new socket programming in python i'm having tough time assigning ip addresses , pickle serializing lists sent server client,
server side:
import pickle import socket udp_ip = '127.0.0.1' udp_port = 8014 fd = socket.socket(socket.af_inet, socket.sock_dgram) fd.bind((udp_ip,udp_port)) x=[] while true: r = fd.recvfrom(2048) x.append(r) print x datas=pickle.dumps(x) reply = r[0] client_address = r[1] #fd.sendto(bytearray(reply,"utf-8"), client_address) fd.sendto(datas,client_address)
client side:
import pickle import socket fd = socket.socket(socket.af_inet, socket.sock_dgram ) fd.getsockname() udp_ip = '127.0.0.1' udp_port = 8014 b=[] print "sign-in" message= raw_input("username :") fd.sendto(message, (udp_ip, udp_port)) while(true): reply = fd.recvfrom(1000) list1=raw_input("\n").lower().strip() if list1=="list": a=pickle.loads(reply) b.append(a) print "here list of ip addr , ports",a else: print("sorry didn't that.")
problem 1- need figure out how assign proper ip addresses both client , server. other ip other localhost returns error, `errno99 cannot assign requested address.
problem 2- pickle serialization fantastic , i'm trying list x server client throws error on client side,
`file"client1.py", line 21, in <module> a=pickle.loads(reply) file "/usr/lib/python2.7/pickle.py", line 1387, in loads file = stringio(str) typeerror: stringio() argument 1 must string or buffer, not tuple
problem 3- still trying understand how client able retrieve other client's ip , port info server's list , contact other client directly (no server involved). understand bytearrays(can rid of them if use pickle serialization)
i appreciate as possible not asking here code entirely of course, show me way , let me know i'm wrong. links examples perfect.
Comments
Post a Comment