How to identify what the server or client is saying? #269
-
Hello @jchristn, back here again. I'm trying to understand and implement file transfer using WatsonTcp, but I have a problem. The client part, when the appropriate method is invoked, looks like this: MemoryStream stream = new MemoryStream(); The context is that the server requests a screenshot from the client, and the client, upon processing the request, sends the aforementioned code. So far, so good. But on the server side, how can I identify that what I receive is a screenshot? The common logic I use is as follows: To send: Connection.ClientSocket.Send("Login|" + Username + "|" + Password); private async void MessageReceived(object sender, MessageReceivedEventArgs args) Taking into account the mess I generate in order to identify the meaning of the communication for both the server and the client, I ask for your help in doing this correctly and efficiently. I can't identify the screenshot because it's an array of bytes, and I can't put a string in front of it. I would greatly appreciate your help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Gu @SnowdenDev nice to hear from you! The approach I would take would be to either A) attach a key-value pair to the message metadata to indicate the message type, or, B) create a single structure that is serialized that includes the data required for any type of message you are sending. Example of A)
Example of B)
|
Beta Was this translation helpful? Give feedback.
-
this seems to work for me: but what would be the logic to classify what I receive on the server, I was looking at the references but I don't understand |
Beta Was this translation helpful? Give feedback.
Hi @SnowdenDev the logic would be to examine the
MessageReceivedEventArgs.Metadata
in your event handler to find theMessageType
key and value. From there you can pass the message data into your handler, whether it's login or something else.