Created
August 22, 2023 05:30
-
-
Save pingkunga/4655488f728663abc3790d17af7ff3fc to your computer and use it in GitHub Desktop.
TCP_JSON#02
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 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