简体   繁体   中英

How to implement sockets on the server side C#?

I'm learning to work with sockets, and every example in every article or book demonstrates how a server should work using a desktop console or wpf application. The authors usually say that the same code can be easily implemented on the server .

Maybe it's easy, but still -- how? Do I have to use WCF or maybe something else? Is there any good book which can help me to become the lord of sockets?

The "same code on the server" comment means you're really developing a communications interface protocol. You send messages in a particular way, and expect to receive in the same way. Eg. fixed length messages vs agreed terminator; how message data is formatted etc.

If you put your code into it's own set of classes you can then host your code in any sort of application - console, wpf as you've stated but also.. windows services. In my case i've got it so that running the app in debug mode runs winforms, but as release mode runs as a service.

The answer to this SO question has some useful links.

Chat service application

I highly recommend Vadym's posts and Stephen Cleary's nito documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM