我需要在客户端用java构造一个字符串并将其发送到服务器进行解码。
我需要client name
他是否要注册("Subscribe"
或"Unsubscribe"
)。
我正在使用 hashmap 来实现它,客户端名称是键和一个以客户端数据作为值的类。
我正在使用UDP
.
那么你认为我应该使用什么来编码和解码请求的最佳方式是什么?
谢谢。
You could use any of the already available formats:
If any of them seem to heavy-weight for you. You could make a simple custom format just for your application. But if I would be in your shoes I would go with with JSON, as you mentioned is 'just' a school assignment, so you should learn something.
Good luck
使用 JSON:
{"client-name": "cow", "action":"subscribe"}