Created
August 22, 2023 06:41
-
-
Save pingkunga/32e527e08425b577d958de56108d64eb to your computer and use it in GitHub Desktop.
TCP_JSON#07
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InvsRequestHandler : AbstractBaseRequestHandler, IRTRequestHandler | |
{ | |
protected override void run() | |
{ | |
try | |
{ | |
while (true) | |
{ | |
NetworkStream ns = clientSocket.GetStream(); | |
StringBuilder response = new StringBuilder(); | |
var buffer = new byte[clientSocket.ReceiveBufferSize+10]; | |
while (ns.DataAvailable) | |
{ | |
int bytes = ns.Read(buffer, 0, clientSocket.ReceiveBufferSize); | |
response.Append(Encoding.Unicode.GetString(buffer, 0, bytes)); | |
} | |
if (String.IsNullOrEmpty(response.ToString())) | |
{ | |
continue; | |
} | |
ParamDTO deserialized = JSONHelper.deserialize<ParamDTO>(response.ToString()); | |
//Your Business Logic | |
IList<BusinnesLogicDTO> resultls= ProcessSomeLogic(param); | |
//... | |
//Serialize Object and Send Result Back to Client | |
Byte[] mb = JSONHelper.serializeObject<IList<BusinnesLogicDT>(resultls); | |
ns.Write(mb, 0, mb.Length); | |
ns.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