I am working with UDP in python 3.8.0, but I am having a problem with my message, once the socket doesn't allow a string, I have to convert the string to binary, so I used message.encode()
, but it comes with an additional b' and ' at the end of the message, how can I remove them?
My code:
import socket
import sys
import config
MY_IP = config.myIP
OTHER_IP = config.otherIp
PORT_NUMBER = config.port_number
# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = (MY_IP, PORT_NUMBER)
message = input("Write a message: ").encode( )
print("Message: ", message)
The output of the result you can see below:
Write a message: a
Message: b'a'
Is there another way to change string to binary?
A new python learner thanks you.