英文:
Java ) choose the token that people can't input or other idea to solve this issue
问题
I'm making a chatting program and encountering issues. I'm trying to tokenize a packet that includes 4 items: Timestamp, sendTime, String sendUserID, String chattingMessage, and String roomNo. When the client-side sends this packet, (packet is string :: String packet;)
, I'm attempting to tokenize it using a special character like (#,@,^ ..)
or something else on the server-side. However, due to the variable nature of chattingMessage (which can include any special character as users can input any character in the message), I'm struggling to choose an appropriate tokenizing character. Does anyone have any ideas or solutions for this issue? I'm quite curious.
英文:
i'm making chattingProgram and got problems..
i try to stringtokenize
packet.
packet includes 4 items.
Timestamp sendTime, String sendUserID, String chattingMessage, String roomNo.
when client-side sends this packet,(packet is string :: String packet;)
i try to tokenize this packet by some special character(#,@,^ ..)
or something else in Server-side
but because of chattingMessage, (chattingMessage can include any special character..(user can input any character in message.. so how to choose my tokenizing character?? ..)
i can't choose the one for appropriate...
Is there anybody have the idea, solution for this issue??
i'm so curious..
答案1
得分: 1
设计数据包,以便在字符串内容之前包含字符串的长度。这样,你就知道字符串在数据包中的结束位置和下一段数据的开始位置。
你可以学习例如BitTorrent的.torrent文件是如何格式化的。设计序列化数据包格式实际上与设计文件格式相同,唯一的区别在于你从哪里读取数据。
英文:
Design the packet so that it includes the length of the strings before the string contents. Then you know where that string ends in your packet and the next piece of data begins.
You can study for example how .torrent files for BitTorrent are formatted. Designing a serialized packet format is really the same as designing a file format, the only difference is where you read the data from.
答案2
得分: 0
将用户消息中的所有\
实例替换为\\
。然后将)
替换为\)
。在检查)
时,请确保它之前没有\
。在向用户显示消息时,删除所有未被另一个\
处理的\
。
英文:
Replace any instances of \
in the user's message with \\
. Then replace )
with \)
. When you check for the )
make sure that there isn't a \
before it. When displaying the message to the user remove all \
s that aren't processed by another \
.
答案3
得分: 0
我认为客户端必须发送byte[]而不是String。
并且数据包必须是POJO,在通信过程中必须进行序列化和反序列化。
英文:
I think client-side must send byte[] instead of String.<br>
And Packet must by POJO which must be serialized/deserialized in process of communication.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论