SuperSocket Study Notes (a)-a complete example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.