Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net.Sockets;
- using GoProtocol;
- namespace ChatClient
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool loggedIn = false;
- Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- s.Connect("localhost",7777);
- while (!loggedIn)
- {
- Console.Write("Username: ");
- string userName = Console.ReadLine();
- Console.Write("Password: ");
- string password = Console.ReadLine();
- s.Send(new Message(MessageType.Login, new string[] { userName, password }).ToByteArray());
- byte[] buffer = new byte[1024];
- s.Receive(buffer);
- Message response = new Message(buffer, 0);
- if (response.Type == MessageType.Error)
- {
- Console.WriteLine("An error occured:");
- Console.WriteLine(response.Parameters[0]);
- Console.WriteLine("Do you want to try again?(yes,no)");
- string input = Console.ReadLine();
- if (input == "no")
- return;
- }
- else if (response.Type == MessageType.Login)
- {
- Console.WriteLine("Login succesful");
- loggedIn = true;
- }
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement