Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace AsyncConnectorTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Enter IP to connect to (with port): ");
- var ip = Console.ReadLine();
- Console.Write("Enter name: ");
- var name = Console.ReadLine();
- var handshake = "name:" + name;
- var client = new TcpClient();
- client.Connect(ip.Split(':')[0], int.Parse(ip.Split(':')[1]));
- var ns = client.GetStream();
- var sw = new StreamWriter(ns);
- Thread.Sleep(1000); // let the server catch up
- sw.WriteLine(handshake);
- Console.WriteLine("Staying connected.. Press ESCAPE to exit.");
- while (true)
- {
- // stay connected
- if (!Console.KeyAvailable) continue;
- var key = Console.ReadKey();
- if (key.Key == ConsoleKey.Escape)
- Environment.Exit(1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement