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.Threading.Tasks;
- using System.Net;
- using System.Net.Sockets;
- namespace WinView___Client
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isConnected = false;
- bool isQuited = false;
- while (!isConnected)
- {
- TcpClient tcpclient = new TcpClient("127.0.0.1", 1200);
- Console.WriteLine("Trying to connect...");
- NetworkStream stream = tcpclient.GetStream();
- Console.WriteLine("Connected to server!");
- isConnected = true;
- while (!isQuited)
- {
- string clientCommand = Console.ReadLine();
- byte[] clientCommandByte = Encoding.Unicode.GetBytes(clientCommand);
- if (clientCommand != "!quit")
- {
- stream.Write(clientCommandByte, 0, clientCommandByte.Length);
- Console.WriteLine(clientCommand);
- }
- else
- {
- string quitMessage = "Client has been disconnected!";
- byte[] quitMessagebyte = Encoding.Unicode.GetBytes(quitMessage);
- stream.Write(quitMessagebyte, 0, quitMessagebyte.Length);
- tcpclient.Close();
- isQuited = true;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement