Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting client.");
            QuicClient client = new QuicClient();

            Console.WriteLine("Connecting to server.");
            QuicConnection connection = client.Connect("127.0.0.1", 11000);   // Connect to peer (Server)

            Console.WriteLine("Connected");

            QuicStream stream = connection.CreateStream(QuickNet.Utilities.StreamType.ClientBidirectional); // Create a data stream

            Console.WriteLine("Create stream with id: " + stream.StreamId.IntegerValue.ToString());

            Console.WriteLine("Send 'Hello From Client!'");
            stream.Send(Encoding.UTF8.GetBytes("Hello from Client!"));        // Send Data
            Console.WriteLine("Waiting for message from the server");
            try
            {
                byte[] data = stream.Receive();                                   // Receive from server
                Console.WriteLine("Received: " + Encoding.UTF8.GetString(data));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void StreamDataReceived(QuicStream stream, byte[] data)
        {
            Console.WriteLine("Stream Data Received: ");
            string decoded = Encoding.UTF8.GetString(data);

            Console.WriteLine(decoded);

            stream.Send(Encoding.UTF8.GetBytes("Ping back from server."));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.ReadKey();
            QuicClient     qClient     = new QuicClient();
            QuicConnection qConnection = qClient.Connect("127.0.0.1", 11000);
            QuicStream     qStream     = qConnection.CreateStream(QuickNet.Utilities.StreamType.ClientBidirectional);

            Console.ReadKey();
            qStream.Send(Encoding.UTF8.GetBytes("Hello from Client!"));
            Console.WriteLine(qStream.Receive().ToString());
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Client");
            QuicClient     client     = new QuicClient();
            QuicConnection connection = client.Connect("127.0.0.1", 18000);   // Connect to peer (Server)

            // Create a Bidirectional data stream
            QuicStream stream = connection.CreateStream(QuickNet.Utilities.StreamType.ClientBidirectional);

            // Send Data
            var message = Console.ReadLine();

            stream.Send(Encoding.UTF8.GetBytes(message));

            // Receive from server (Blocks)
            byte[] data = stream.Receive();
            Console.ReadKey();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            QuicClient client = new QuicClient();

            // Connect to peer (Server)
            QuicConnection connection = client.Connect("127.0.0.1", 11000);
            // Create a data stream
            QuicStream stream = connection.CreateStream(QuickNet.Utilities.StreamType.ClientBidirectional);

            // Send Data
            stream.Send(Encoding.UTF8.GetBytes("Hello from Client!"));
            // Wait reponse back from the server
            byte[] data = stream.Receive();

            Console.WriteLine(Encoding.UTF8.GetString(data));

            Console.ReadKey();
        }
Ejemplo n.º 6
0
        public Req send_on_quic_protocol(string content,int port)
        {
            Req request = new Req();
            int ms = 0;
            int byteNumber = -1;
            request.Content = content;
            //Console.WriteLine("Starting client.");
            QuicClient client = new QuicClient();
            request.timeSended = DateTime.Now.ToLocalTime();
            QuicConnection connection = client.Connect("127.0.0.1", port);   // Connect to peer (Server)

            QuicStream stream_quic = connection.CreateStream(QuickNet.Utilities.StreamType.ClientBidirectional); // Create a data stream

            byte[] messageBytes = null;

            string aaa = JsonConvert.SerializeObject(request);
            messageBytes = System.Text.Encoding.UTF8.GetBytes(aaa);
            //Console.WriteLine("Send 'Hello From Client!'");
            stream_quic.Send(messageBytes);        // Send Data
            //Console.WriteLine("Waiting for message from the server");
            try
            {
                byte[] data = stream_quic.Receive();
                byteNumber = data.Length;
                DateTime timeRecieved = DateTime.Now.ToLocalTime();
                string message = cleanMessage(data);
                // Receive from server
                Req request_back = JsonConvert.DeserializeObject<Req>(message); // Deserialize
                request.timeRecieved = timeRecieved;
                TimeSpan span = request_back.timeRecieved - request_back.timeSended;
                request.number_of_bytes = data.Length;
                //request_back.timeRecieved.mili
                ms = (int)span.TotalMilliseconds;
                request.totalTime = ms;

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return request;
        }