I have a client-server application which communicates over TCP/IP.
I use System.Net.Sockets.Socket
type object for ascnyronous communication over TCP. Basicly i open connection send/receive data and close connection. And my implementation is based on Socket type objects.
Now i need to use a third-party dll to do something. This dll expects a System.IO.Stream
type object. So i need to get Stream object of my Socket object.
How can i do that?
Thank you.
Pretty simple really. The constructor for the NetworkStream class accepts a socket to wrap:
http://msdn.microsoft.com/en-us/library/system.net.sockets.networkstream.aspx
// NOTE: This demonstrates disposal of the stream when you are
// done with it- you may not want that behavior.
using (var myStream = new NetworkStream(mySocket)) {
my3rdPartyObject.Foo(myStream);
}
Try looking at System.Net.Sockets.SocketType.Stream ?
Or try looking at the System.Net.Sockets.NetworkStream ?
http://msdn.microsoft.com/en-us/library/system.net.sockets.networkstream.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With