What is a good tutorial/howto on .net / c# socket programming [closed]
-
01-07-2019 - |
Question
I'm porting old VB6 code that uses the Winsock control to C#. I haven't done any socket programming and I wonder if anyone has a good reference/tutorial/howto that I can use to start getting up to speed.
I'm appealing to the hive mind while I proceed with my generally unproductive googling.
I'm using UDP, not TCP at this time.
Solution
The August 2005 MSDN Magazine had an article about System.Net.Sockets and WinSock:
OTHER TIPS
- I recommend the asynchronous model for most applications, especially if you want performance or applications that don't hang as soon there is a network problem. For this the MSDN articles on Socket.BeginConnect and Socket.BeginReceive are good places to start.
- The following link is not .NET, but many of the recommendations still hold: http://tangentsoft.net/wskfaq/articles/lame-list.html
Are you working on: a client (TCPClient) or a server (TCPListener)
Just a heads up:
I would recommend first working with TCP rather than UDP. UDP doesn't automatically redeliver lost packets like TCP so it will add another element to the equation that will probably just confuse you as you're just starting out.
Building a socket client is relatively easy using the TCPClient class available in the .Net library. TCPListener is easy enough to use for a single client but if you're hoping to develop some server type application (IE: Handling multiple connections.) the real hurdle you'll have to overcome is understanding multithreading.
Once you've played around with single connection sockets I suggest you read up on multithreading.