Python"s module socket uses ecv ()
to constantly listen to the request data sent by the client, including the empty string bounded"
. How to identify the empty request and block it?
Server side:
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("127.0.0.1", 8080))
server.listen(50)
while True:
data, addr = server.accept()
info = b"OK"
while True:
buffer = data.recv(2) -sharp b""
if buffer == b"":
info = b"Bad request"
break
data.send(info)
data.close()
client:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 8080))
data = b""
s.send(data)
data_get = s.recv(1024) -sharp
s.close()