c# - NetworkStream.Write vs. Socket.Send -


i have c# application use custom ftp library for. right im using socket.send send data wondering if better initiate networkstream socket , use networkstream.write instead.

are there advantages using 1 on other?

the advantage of networkstream derives fact stream. disadvantage of socket common code reads , writes abstract i/o sources stream cannot handle socket.

the main use case networkstream have code elsewhere reads or writes stream, , wish use socket. know if in situation , networkstream big help!

say example had communications library , supported serializing messages files, named pipes , tcp/ip. ideal choice i/o class stream. serialization methods accept filestream, pipestream, or networkstream. accept memorystream. benefit of abstraction because after we've created stream, method can interact without knowing kind of stream is.

in sense, networkstream uses adapter design pattern. adapts socket api stream api clients expecting stream can use it.

so finally, question, if networkstream stream adapter socket, 1 should use? well, if need stream, networkstream choice. if don't need stream, can use whichever api comfortable with. if using socket successfully, there no pressing reason switch networkstream.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -