Simplest way for implementing an extremly simple Server? (C#)
I'm currently writing a simple application for some friends of mine. There is a pretty small part which contains some client-server communication. Protocolls like http are far to ov开发者_运维百科erloaded with unnecessary stuff I don't need.
Here is all the communication I need to implement:
(Request -> Response)
* {AccountID} -> {AccountBalance}
* {AccountID,newBalance} -> {AccountBalance}
* {AccountID,ItemID,Amount} -> {AccountBalance}
* {ItemID} -> {ItemValue}
All values are integer. AccountIDs and ItemIDs are distinguished. AccountBalances and ItemValues are always positiv.
Since the application will only be used in a private LAN security is not important.
I already tried using a httpListener for that, but it seems like it wasn't suitable for my needs.
You should consider providing these methods over WCF. That is the simplest way to achieve what you want.
See A Simple Sample: WCF Service
You could also write your own TCP based server/client - it's quite simple to do in C#.
This makes for a reasonable exmple, then you can customize it to your needs:
http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server
As note in the answer from Hasan WCF is the fastest and easiest protocol to implement.
If you want something lower level and parse bits and bytes yourself TcpClient
is the way to go.
精彩评论