0

i have an issue in send str command from server to client. i wanna sent str value (for ex: "Hello, You Are Connected to the server"). but in client program show (b'Hello, You Are Connected to the server) how i can clear the "b'....'"?
Server:

#The Server Socket Program
import socket
s= socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(("localhost",5225))
s.listen(5)
while True:
    conn,addr = s.accept()
    print("Recinving a Connection from: ",addr)
    conn.send(str.encode('Hello, You Are Connected to the server'))
    conn.close()

Client:

#The Client Program
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("localhost",5225))
s.send(str.encode("Hello Server"))
data=s.recv(2048)
print(data) 
s.close()

enter image description here

iMohammad
  • 83
  • 1
  • 8
  • `print(data.decode('utf-8'))` If you encode, you must decode. – cs95 Sep 07 '17 at 22:22
  • That's just notation that it is a byte string. You can just `s.send(b'hello')` or `s.send('hello'.encode())`. You can't send Unicode strings directly...they must be encoded to send and decoded after receive. – Mark Tolonen Sep 08 '17 at 06:08

0 Answers0