Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1.      public async Task AcceptClients()
  2.         {
  3.             var listener = new TcpListener(IPAddress.Any, GlobalConst.LobbyServerPort);
  4.            
  5.             listener.Start();
  6.             while (true) {
  7.                 if (listener.Pending()) {
  8.                     var client = await listener.AcceptTcpClientAsync();
  9.                     Console.WriteLine("Accepting conneciton {0}", client);
  10.                     ProcessClient(client);
  11.                 }
  12.             }
  13.         }
  14.  
  15.         public async Task ProcessClient(TcpClient client)
  16.         {
  17.             try {
  18.                 var stream = client.GetStream();
  19.                 var reader = new StreamReader(stream, Encoding);
  20.                 await Write(stream, "TASServer 91.0 Test 123");
  21.                 while (true) {
  22.                     var line = await reader.ReadLineAsync();
  23.                     Console.WriteLine(line);
  24.                     if (line != null && line.StartsWith("LOGIN")) {
  25.                         await Task.Run(async () => {
  26.                             Account acc;
  27.                             using (var db = new ZkDataContext()) {
  28.                                 acc = Account.AccountVerify(db, "test", "test");
  29.                             }
  30.                             await Write(stream, "LOGINACCEPTED " + acc.Name);
  31.                         });
  32.                     }
  33.                 }
  34.             } catch (Exception ex) {
  35.                 Console.WriteLine(ex.ToString());
  36.             }
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement