Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net.Sockets;
  6. using GoProtocol;
  7.  
  8. namespace ChatClient
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             bool loggedIn = false;
  15.             Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  16.             s.Connect("localhost",7777);
  17.             while (!loggedIn)
  18.             {
  19.                 Console.Write("Username: ");
  20.                 string userName = Console.ReadLine();
  21.                 Console.Write("Password: ");
  22.                 string password = Console.ReadLine();
  23.  
  24.                 s.Send(new Message(MessageType.Login, new string[] { userName, password }).ToByteArray());
  25.                 byte[] buffer = new byte[1024];
  26.  
  27.                 s.Receive(buffer);
  28.                 Message response = new Message(buffer, 0);
  29.                 if (response.Type == MessageType.Error)
  30.                 {
  31.                     Console.WriteLine("An error occured:");
  32.                     Console.WriteLine(response.Parameters[0]);
  33.                     Console.WriteLine("Do you want to try again?(yes,no)");
  34.                     string input = Console.ReadLine();
  35.                     if (input == "no")
  36.                         return;
  37.                 }
  38.                 else if (response.Type == MessageType.Login)
  39.                 {
  40.                     Console.WriteLine("Login succesful");
  41.                     loggedIn = true;
  42.                 }
  43.             }
  44.  
  45.             Console.ReadLine();
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement