question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is Bidirectional working (client to server to client)?

See original GitHub issue

Hello again,

I’m not a 100% sure that I understand the meaning of “Bidirectional” But in your console client sample, I’ve added

// in the QuicNet.Tests.ConsoleClient.Program.Main
context.OnDataReceived += Context_OnDataReceived;

// in the QuicNet.Tests.ConsoleClient.Program
private static void Context_OnDataReceived(QuicStreamContext obj)
{
      Console.WriteLine("Data Received!");
}

I saw that in your server code you send an “Echo!”, and was expecting a way to get the data through the delegate, but for some reason, I’m not getting anything. I’ve traced in the code, and the bytes are sent successfully, but maybe at a lower level, the data is not processed in the client?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
angedelamortcommented, Jan 10, 2019

Hello, I just did a proof of concept while playing with the code in order to understand it better. I’ve added the code if you’re interested.

I found out that if you call the “new QuicStream”, it doesn’t work. When you look at the CreateStream in Connection, it uses “_streams.Add(streamId, stream);”. So maybe QuicStream shouildn’t be available (internal).

Also, I was sure that you could play with the streamID in order to send multiple message using the same connection. But from what I understand, every time you want to do a new “Send”, you need to create a new connection. Am I right?

Thanks

Class QuicClient2

public class QuicClient2
    {
        private readonly QuicClient client;
        private QuicConnection connection;
        private QuicStream stream;
        private StreamType streamType;

        public QuicClient2()
        {
            client = new QuicClient();
        }

        public void Connect(string ip, int port, StreamType streamType = StreamType.ClientBidirectional)
        {
            connection = client.Connect(ip, port);
            this.streamType = streamType;
        }

        public void Connect(IPEndPoint endpoint, StreamType streamType = StreamType.ClientBidirectional)
        {
            connection = client.Connect(endpoint.Address.ToString(), endpoint.Port);
            this.streamType = streamType;
        }

        public async Task Send(byte[] data)
        {
            if (connection == null)
                throw new InvalidOperationException("Need to call Connect before calling Send()");

            try
            {

                // TODO: might need to lock, but not sure if ++ is an atomic operation
                stream = connection.CreateStream(streamType);
                await Task.Run(() => stream.Send(data));
                OnDataSended?.Invoke(this, new DataEventArgs(data));
            }
            catch (Exception ex)
            {
                OnError(this, new ErrorEventArgs(ex));
            }
        }

        public async Task Receive()
        {
            if (connection == null)
                throw new InvalidOperationException("Need to call Connect before calling Send()");

            try
            {
                var data = await Task.Run(() => stream.Receive());
                OnDataReceived?.Invoke(this, new DataEventArgs(data));
            }
            catch (Exception ex)
            {
                OnError(this, new ErrorEventArgs(ex));
            }
        }

        public class DataEventArgs : EventArgs
        {
            public DataEventArgs(byte[] data)
            {
                Data = data;
            }

            public byte[] Data { get; }
        }

        public delegate void MessageEvent(object sender, DataEventArgs args);

        public event MessageEvent OnDataSended;
        public event MessageEvent OnDataReceived;
        public event ErrorEventHandler OnError;

Class Program from client

static void Main(string[] args)
        {
            Console.WriteLine("Starting client.");
            QuicClient2 client = new QuicClient2();

            client.OnDataSended += Stream_OnDataSended;
            client.OnDataReceived += Stream_OnDataReceived;
            client.OnError += Stream_OnError;

            Console.WriteLine("Connecting to server.");
            client.Connect("127.0.0.1", 11000);
            Console.WriteLine("Connected");

            // TODO1: Not sure about the usage, not as clean as I though. But we have different behavior depending on the StreamType
            var taskSend = client.Send(Encoding.UTF8.GetBytes("Hello from Client!"));
            var taskReceived = client.Receive();
            taskReceived.Wait();

            Console.ReadKey();
        }

        private static void Stream_OnError(object sender, System.IO.ErrorEventArgs e)
        {
            Console.WriteLine(e.GetException().Message);
        }

        private static void Stream_OnDataReceived(object sender, DataEventArgs args)
        {
            Console.WriteLine($"Received: {Encoding.UTF8.GetString(args.Data)}");
        }

        private static void Stream_OnDataSended(object sender, DataEventArgs args)
        {
            Console.WriteLine($"Sent: {Encoding.UTF8.GetString(args.Data)}");
        }
0reactions
angedelamortcommented, Jan 11, 2019

I was thinking with the current implementation, it doesn’t seem far from a “websocket” implementation in UDP. That’s why I was asking.

Thanks for your reply

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSocket: Simultaneous Bi-Directional Client-Server ...
Conclusion. Overall, WebSocket is a new web protocol that can allow real-time communication between the server and client simultaneously.
Read more >
bi-directional communication between server and client
Can anybody suggest a javascript/nodejs solution for bi-directional communication between server and client. The application flow will be ...
Read more >
Core concepts, architecture and lifecycle
Bidirectional streaming RPCs where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so ...
Read more >
HTTPS for bidirectional communication
The "client" (the hardware device) acts as a server when it receives a command by the remote user. But acts as a client...
Read more >
Concluded WG BiDirectional or Server-Initiated HTTP (hybi)
The BiDirectional or Server-Initiated HTTP (HyBi) working group defines the WebSocket Protocol, a technology for bidirectional communication between an HTTP ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found