I have a server in java which is supposed to transfer an IP address and a number to a client in a single message. Here is the transfer code:
int indexMin;
int num;
.
.
.
String found = String.format("10.0.0.%1$d %2$d", indexMin, num);
byte[] foundByte = found.getBytes();
the length of indexMin and num is variable (and they may have 1 or 2 or ... digits).
I'm using Python on the client side. I want my client to receive this string and differentiate between the address (for example 10.0.0.5) and the second value which is separated by space. Here is the code that I'm using on the client:
def read_udp(s):
data,addr = s.recvfrom(1024)
print("received message:", data)
.
.
.
address = #adress part
num = #2nd number part
Since the length of the received string is variable, how can I extract the address
and the num
? Should I check the characters of the received message one by one to find the space
or is there a better way?