0

sir i am developing server client program in python. when i try to run the client it gives me an error, saying

clientSocket.sendto(message, addr) TypeError: a bytes-like object is required, not 'str'

what is the possible reson for this.? how to pass it as a bytes strings? any help would be highly aprriciated

import time
from socket import *

for pings in range(10):
clientSocket = socket(AF_INET, SOCK_DGRAM)
clientSocket.settimeout(1)
message = 'test'
addr = ("127.0.0.1", 12000)

start = time.time()
clientSocket.sendto(message, addr)
try:
    data, server = clientSocket.recvfrom(1024)
    end = time.time()
    elapsed = end - start
    print ("%s %d %d") % (data, pings, elapsed)
except timeout:
    print ("REQUEST TIMED OUT")
2
  • Are you using Python 2 or Python 3? Please tag your question accordingly. Commented Nov 28, 2017 at 16:10
  • python 3 sir, thnks sir i have figured it out Commented Nov 28, 2017 at 16:12

1 Answer 1

0

clientSocket.sendto(message.encode('utf-8'), addr)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.