Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
808 B
5
Indexable
internal class Program
    {
        private static TcpClient tcpClient;
        private static NetworkStream clientStream;
        private static string clientName;

        public static void Main(string[] args)
        {
            Console.WriteLine("Enter your name: ");
            clientName = Console.ReadLine();

            StartClient();

            Console.ReadLine();
        }

        public static void StartClient()
        {
            tcpClient = new TcpClient("127.0.0.1", 8888);
            clientStream = tcpClient.GetStream();

            byte[] name = Encoding.ASCII.GetBytes(clientName);
            clientStream.Write(name, 0, name.Length);
            clientStream.Flush();

            Console.WriteLine("Connected to the server...");
        }
    }
Leave a Comment