16BPP.net
 
 
 
 
 Previous Page   Socket Class Intro - Recap   Next Page 

Socket Class Intro - Recap

 

C Server on the left, C# client on the right

 

There wasn't too much that was covered here, but we got our feet wet with using the raw Socket class.  In the next section we will cover usage of the async methods in Socket.  Get ready for callbacks everywhere!

 

 

Why is using the Socket class directly more efficient than something like TcpClient or UdpClient?

As I said before, classes like TcpClient and UdpClient have and underlying Socket object (which can actually be accessed via the Client property in both).  "Why would we even want to use Socket if it's more complicated?"  you might ask.

If you chose to use TcpClient or UdpClient there is a slight amount of overhead versus working directly with a Socket.  If you truly need a high octane riced app, then  go with Socket.  The performance/efficiency benefits mostly come from using the async methods of Socket, which are all callback based.  Yes, yes.  TcpClient and UdpClient do have async methods too, but the Socket class has a lot more of them which gives you way more flexibility than the other two do.

 Previous Page   Socket Class Intro - Recap   Next Page