Server
#!/usr/bin/python3
import socket
from time import ctime
HOST = ''
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST, PORT)
udpSerSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udpSerSock.bind(ADDR)
while(True):
print('waiting for message...')
data, addr = udpSerSock.recvfrom(BUFSIZ)
udpSerSock.sendto(data, addr)
print('...received from and returned to:', addr)
udpSerSock.close()
#END#
Client
#!/usr/bin/python3
import socket
HOST = 'localhost'
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST, PORT)
udpCliSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while(True):
data = input('> ')
if not data:
break
udpCliSock.sendto(data, ADDR)
data, ADDR = udpCliSock.recvfrom(BUFSIZ)
if not data:
break
print(data)
udpCliSock.close()
#END#
What is the relevance of BUFSIZE? When and why do I need to wory aobut BUFSIZ? Also, when I run this program this is the message I get on the client screen after typing anything and pressing enter.
udpCliSock.sendto(data, ADDR)
TypeError: 'str' does not support the buffer interface
One last thing, how could these to programs me modified so that the server and client simply sent and received a simple 'hello world'? Thanks.