Python Networking responding wtih 'b' -
i've started python networking, , after looking @ few internet tutorials, gave go... problem is, whenever response sever, prints in:
recieved from: (host & port)b'hey' - haven't put b anywhere.
here server code:
import socket import tkinter import time import sys def main(): top = tkinter.tk() top.configure(background='black') host = '10.0.0.2' port = 5000 s = socket.socket() s.bind((host, port)) s.listen(1) c, addr = s.accept() while true: con = tkinter.label(top, text="connection from: " + str(addr), bg='red', fg='white').pack() data = c.recv(1024) if not data: break conn = tkinter.label(top, text="recieved from: " + str(addr) + str(data), bg='black', fg='white').pack() top.mainloop() c.close() main()
and client:
import socket def main(): host = '10.0.0.2' port = 5000 s = socket.socket() s.connect((host, port)) message = input("> ") while message != 'quit': s.send(message.encode('ascii')) message = input(">") s.close() main()
thanks input - i'm not @ yet! (my hosts aren't computer that's not issue)
when call socket.recv() in python 3 returns bytes object, not normal string. can convert normal string follows:
data.decode('utf-8')
Comments
Post a Comment