1

i am trying to play around with python 3.5 using udp comunication but i cant seem to ever get the socket library to work it always give this error

Traceback (most recent call last):
   File "C:\Users\Nicholas Hendricks\Desktop\udpServer.py", line 8, in  <module>
   bytes(HOST)
TypeError: string argument without an encoding

and here is my Code:

import socket
import time

HOST = 'localhost'
PORT =  5454
data = "sup bruh"

bytes(HOST)
bytes(PORT)
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)


while 1:
    s.sendto(data,(HOST,PORT))
    print ("sent:" + data)
Torxed
  • 22,866
  • 14
  • 82
  • 131

1 Answers1

0

The problem is that bytes() assumes a encoding argument like so:

HOST = bytes(HOST, 'utf-8')

But I don't see why you convert port to bytes, I'm on the phone so can't check but isn't it supposed to be a integer?

And you will probably want to convert data as well:

data = bytes(data, 'utf-8')
Torxed
  • 22,866
  • 14
  • 82
  • 131