txdv / LibuvSharp

.NET bindings for libuv
176 stars 41 forks source link

Question about AcceptAsync in TcpAsync sample #19

Open psantosl opened 7 years ago

psantosl commented 7 years ago

Hi there, I'm trying to understand how the library works.

I wrote the following client code replacing the Client in TcpAsync:

        public static async Task Client2()
        {
            try
            {
                using (System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient())
                {
                    client.Connect(Default.IPEndPoint);

                    var st = client.GetStream();

                    using (BinaryWriter writer = new BinaryWriter(st))
                    using (BinaryReader reader = new BinaryReader(st))
                    {
                        writer.Write("Hello ");
                        writer.Flush();
                        writer.Write(true);
                        writer.Flush();
                        writer.Write(" good to go");

                        string s = reader.ReadString();

                        Console.Write(s);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Client Exception:");
                Console.WriteLine(e);
            }
        }

Well, the server never returns from AcceptAsync().

I'm familiar with socket programming, but not this.

Is this implementation somehow bound to use strings or something? I mean, shouldn't I be able to read the bytes sent by the client?

Thanks!

txdv commented 7 years ago

https://github.com/txdv/LibuvSharp/blob/master/Examples/CrossAsync.cs is doing exactly what you want to

Please provide the entire code if you me want to debug your specific modified case

psantosl commented 7 years ago

All I did was to modify your TcpAsync.cs example, adding my client code as above instead of the Client(). That's all. Just copy/paste this client code in your example and invoke it on Main.

I'll check CrossAsync.cs :-) Thanks.