예제 #1
0
        /// <inheritdoc />
        public Task RunAsync()
        {
            using RawStreamConnection client = new RawStreamConnection(ProtocolType.Tcp, Constants.DefaultEndPoint);
            client.Bind(Constants.ClientEndPoint);
            Console.WriteLine($"[Client] Bound to {client.LocalEndPoint}");

            client.ConnectAsync(Constants.ServerEndPoint).GetAwaiter().GetResult();
            Console.WriteLine($"[Client] Connected to {client.RemoteEndPoint}");

            byte[] packet  = new byte[Constants.PacketSize];
            byte[] message = Constants.ServerEncoding.GetBytes("Hello World!");

            int sentBytes;

            do
            {
                message.CopyTo(packet, 0);

                sentBytes = client.SendAsync(0, packet).GetAwaiter().GetResult();
                Console.WriteLine($"[Client] Sent {sentBytes} bytes to {client.RemoteEndPoint}");

                Thread.Sleep(1000);
            } while (sentBytes > 0);

            client.DisconnectAsync().GetAwaiter().GetResult();
            Console.WriteLine($"[Client] Disconnected from {client.RemoteEndPoint}");

            client.Close();

            return(Task.CompletedTask);
        }
            static void Instantiate()
            {
                using RawStreamConnection conn = ConnectionFactory();
                conn.Bind(ClientLocalEndPoint);

                conn.Start();

                conn.Close();
            }
 public static bool Initialize(string hostname, int port)
 {
     try
     {
         Stream = new RawStreamConnection(hostname, port);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #4
0
 /// <inheritdoc />
 public Task RunAsync()
 {
     using RawStreamConnection server = new RawStreamConnection(ProtocolType.Tcp, Constants.DefaultEndPoint);
     server.Bind(Constants.ServerEndPoint);
     Console.WriteLine($"[Server] Bound to {server.LocalEndPoint}");