First, what is SuperSocket
The following is the author's introduction
Execute the following command to get the SuperSocket project
$ git clone https://github.com/kerryjiang/supersocket
II. Structure of the project
Third, the development process
1. Create a new console project ConsoleApp
1.1 Referencing related projects
1.2 Introduction of log files from solution Items
1.3 Set the Log4net file property of Supersocket.socketbase45 to "copy to local"
2. Write the Main method
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingSupersocket.socketbase;7 8 namespaceConsoleApp9{Ten classProgram One{ A Static voidMain (string[] args) -{ -var appServer =NewAppServer (); the intPort = 8888; - if(!appserver.setup (port)) -{ -Console.WriteLine ("Port Setup failed"); +Console.readkey (); - return; +} A //When connected atappserver.newsessionconnected + = appserver_newsessionconnected; - //When receiving information -Appserver.newrequestreceived + = appserver_newrequestreceived; - //When service is turned off -appserver.sessionclosed + = appserver_sessionclosed; - if(!appserver.start ()) in{ -Console.WriteLine ("failed to start service"); toConsole.readkey (); + return; -} theConsole.WriteLine ("Service started successfully, enter Q to exit"); * $ while(true)Panax Notoginseng{ -var str = console.readline (); the if(str. ToLower (). Equals ("Q")) +{ A Break; the} +} -Console.WriteLine (); $Appserver.stop (); $Console.WriteLine ("Service stopped, press any key to exit"); -Console.readkey (); -} the - Private Static voidAppserver_newsessionconnected (appsession session)Wuyi{ theSession. Send ("Hello world!"); -} Wu - Static voidAppserver_newrequestreceived (appsession session, SuperSocket.SocketBase.Protocol.StringRequestInfo Requestinfo) About{ $ Switch(RequestInfo.Key.ToLower ()) -{ - Case"1": -Session. Send ("You input 1"); A Break; + Case"2": theSession. Send ("You input 2"); - Break; $ default: theSession. Send ("Unknow"); the Break; the} the} - in Static voidAppserver_sessionclosed (appsession session, Closereasonvalue) the{ theSession. Send ("Service is down"); About} the} the} the
View Code
3. Run the project, using Telnet as the client
Four. Next is to see the source code step by step debugging
SuperSocket Study Notes (a)-a complete example