Skip to content

Instantly share code, notes, and snippets.

@pingkunga
Last active August 22, 2023 06:35
Show Gist options
  • Save pingkunga/2879c7a2150a6a51859531310c1c652d to your computer and use it in GitHub Desktop.
Save pingkunga/2879c7a2150a6a51859531310c1c652d to your computer and use it in GitHub Desktop.
TCP_JSON#04
public class InvsRequestHandler : AbstractBaseRequestHandler, IRTRequestHandler
{
protected override void run()
{
try
{
while (true)
{
NetworkStream ns = clientSocket.GetStream();
object deserialized =((IFormatter)new BinaryFormatter()).Deserialize((Stream)ns);
ParamDTO param = (ParamDTO)deserialized;
//Your Business Logic
IList<BusinnesLogicDTO> resultls = ProcessSomeLogic(param);
//...
//Serialize Object and Send Result Back to Client
BinaryWriter bw = new BinaryWriter(ns);
MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, resultls);
bw.Write(ms.ToArray());
bw.Flush();
}
}
catch (Exception wex)
{
clientSocket.Close();
logger.Error(wex.Message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment