Get socket object stream in C #

I have a client-server application that communicates via TCP / IP.
I am using an object of type System.Net.Sockets.Socket for asronic communication over TCP. Basically, I open the data for sending / receiving connections and closed connections. And my implementation is based on objects like Socket.
Now I need to use a third-party dll to do something. This dll expects an object of type System.IO.Stream . So I need to get the Stream object of my Socket .
How can i do this?
Thanks.

+8
c # stream sockets
source share
2 answers

Pretty simple. The constructor of the NetworkStream class accepts a socket for porting:

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); } 
+15
source share

Try looking at System.Net.Sockets.SocketType.Stream?

Or try a look at System.Net.Sockets.NetworkStream?

http://msdn.microsoft.com/en-us/library/system.net.sockets.networkstream.aspx

+1
source share

All Articles