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
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..
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.
Replace any instances of
\ in the user's message with
\\. Then replace
\). 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
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.