Reputation: 1465
Is it possible to send null byte through internet so that the other side can read it properly without truncation at null byte position?
For example:
str = "\xab\xcd\x00\x12\xf6\xbe"
The other side can only read \xab\xcd now.
Upvotes: 0
Views: 5078
Reputation: 881805
Sure, the task is trivial, if the server is receiving binary data correctly. For example, server side:
from socket import *
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('', 12000))
while True:
message, address = serverSocket.recvfrom(1024)
print 'Server received', repr(message)
serverSocket.sendto(message + message, address)
and client side
from socket import *
message = '\xab\xcd\x00\x12\xf6\xbe'
clientSocket = socket(AF_INET, SOCK_DGRAM)
clientSocket.sendto(message, ('127.0.0.1', 12000))
data, server = clientSocket.recvfrom(1024)
print 'client received:', repr(data)
shows it working perfectly (running client and server on two terminals on the same machine, given the IP address I'm using here:-).
Upvotes: 2