Skip to content

Instantly share code, notes, and snippets.

@pingkunga
Created August 22, 2023 05:30
Show Gist options
  • Save pingkunga/4655488f728663abc3790d17af7ff3fc to your computer and use it in GitHub Desktop.
Save pingkunga/4655488f728663abc3790d17af7ff3fc to your computer and use it in GitHub Desktop.
TCP_JSON#02
public void sendRequest(ParamDTO message)
{
try
{
NetworkStream ns = clientSocket.GetStream();
ns.WriteTimeout = WriteTimeOut;
BinaryWriter bw = new BinaryWriter(ns);
MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(memoryStream, obj);
bw.Write(ms.ToArray());
bw.Flush();
}
catch (System.Runtime.Serialization.SerializationException se)
{
throw new DSException("sendRequest-001", "Serialization Exception", EXCEPTION_LEVEL.System, se);
}
catch (ObjectDisposedException disposedException)
{
throw new DSException("sendRequest-002", "Object Disposed Exception", EXCEPTION_LEVEL.System, disposedException);
}
}
public object getResult()
{
try
{
NetworkStream ns = clientSocket.GetStream();
ns.ReadTimeout = ReadTimeOut;
object result =((IFormatter)new BinaryFormatter()).Deserialize((Stream)ns);
return result;
}
catch (ObjectDisposedException disposedException)
{
throw new WmslException("", "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