Skip to content

Question about AcceptAsync in TcpAsync sample #19

@psantosl

Description

@psantosl

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions