The server is Java and the client is Python.
Java sends a string to writeUTF.
Server code.
public void sendPacket(String packet) {
try {
out.writeUTF(packet);
out.flush();
} } catch (IOException e) {
}
}
sendPacket(WebAction.Index.getServerMessage());
Client code.
soc.connect(("127.0.0.1", 7824))
writeString(soc, "ServerMsg&")
msg = soc.recv(1024)
Below is a picture of the problem.
![alt text][1]
'In addition, there are times when numbers are added and sometimes letters are added. I posted a few questions, but I'm posting them again because you gave me a lot of good answers. Thank you for your time.
[1]: http://res.cloudinary.com/eightcruz/image/upload/v1456174690/sm2pm47oik0ldz0uoz1u.png
java python
I don't know why, but if there's always a strange character in front of the string,
HOST='127.0.0.1'
PORT=5007
s=socket(AF_INET,SOCK_STREAM)
#s.bind(HOST, PORT)
s.connect(('127.0.0.1', 8821))
data=s.recv(1024)
data = data[2:]
s.close()
print('Received : %s' % data)
data = data[2:]
I think we can use this method of cutting the first letter.
© 2024 OneMinuteCode. All rights reserved.