Skip to content

Instantly share code, notes, and snippets.

@pingkunga
Created August 22, 2023 06:39
Show Gist options
  • Save pingkunga/49c68dcd581ded0da2b8a00654ee8cbf to your computer and use it in GitHub Desktop.
Save pingkunga/49c68dcd581ded0da2b8a00654ee8cbf to your computer and use it in GitHub Desktop.
TCP_JSON#06
public void sendRequest(ParamDTO message)
{
try
{
NetworkStream ns = clientSocket.GetStream();
ns.WriteTimeout = WriteTimeOut;
Byte[] mb = serializeObject<RequestDictionaryMessage>(message); //PING
ns.Write(mb, 0, mb.Length);
ns.Flush();
}
catch (System.Runtime.Serialization.SerializationException se)
{
throw new WmslException("", "Serialization Exception", EXCEPTION_LEVEL.System, se);
}
catch (ObjectDisposedException disposedException)
{
throw new WmslException("", "Object Disposed Exception", EXCEPTION_LEVEL.System, disposedException);
}
}
public T getResult<T>()
{
try
{
NetworkStream ns = clientSocket.GetStream();
ns.ReadTimeout = ReadTimeOut;
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));
}
T result = deserialize<T>(response.ToString());
return result;
}
catch (ObjectDisposedException disposedException)
{
throw new DSException("", "Object Disposed Exception", EXCEPTION_LEVEL.System, disposedException);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment