nterry / AwesomeSockets

A fast, lightweight, and easy to use socket library for C#.
Other
156 stars 35 forks source link

How do I read response? #14

Closed GuerrillaCoder closed 4 years ago

GuerrillaCoder commented 6 years ago

I have setup example from the main page with a different address (a whois server on port 43) and it runs ok with no exception but I cannot see any of the response data.

This line:

Tuple<int, EndPoint> received = AweSock.ReceiveMessage(server, inBuf);

I look in received inside debugger and cant see any value or byte array to read. Sorry for basic question but I can't figure it out from example. How do I read response?

nterry commented 6 years ago

I’d have to see your code to diagnose the problem

On Mon, Mar 19, 2018 at 9:33 PM GuerrillaCoder notifications@github.com wrote:

I have setup example from the main page with a different address (a whois server on port 43) and it runs ok with no exception but I cannot see any of the response data.

This line:

Tuple<int, EndPoint> received = AweSock.ReceiveMessage(server, inBuf);

I look in received inside debugger and cant see any value or byte array to read. Sorry for basic question but I can't figure it out from example. How do I read response?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nterry/AwesomeSockets/issues/14, or mute the thread https://github.com/notifications/unsubscribe-auth/AAxwllwe1m3dze8NNkND9U1eNSW1xVHBks5tgHiMgaJpZM4SxP2w .

GuerrillaCoder commented 6 years ago

Here is is


            var lookup = new LookupClient();
            var result = lookup.QueryAsync("whois.verisign-grs.com", QueryType.ANY).Result;

            var record = result.Answers.ARecords().FirstOrDefault();
            var address = record?.Address;

            //Client-side code
            ISocket server = AweSock.TcpConnect(address.ToString(), 43);

            AwesomeSockets.Buffers.Buffer inBuf = AwesomeSockets.Buffers.Buffer.New();
            AwesomeSockets.Buffers.Buffer outBuf = AwesomeSockets.Buffers.Buffer.New();

            //Lets send some data to the server! Make a Buffer object and populate it with some data like so:
            AwesomeSockets.Buffers.Buffer.ClearBuffer(outBuf);
            AwesomeSockets.Buffers.Buffer.Add(outBuf, "google.com\r\n");
            AwesomeSockets.Buffers.Buffer.FinalizeBuffer(outBuf);

            //Now lets send it to the server!
            int bytesSent = AweSock.SendMessage(server, outBuf);

            //And receive any inbound messages as well. Received datga will be stored in inBuf. 
            Tuple<int, EndPoint> received = AweSock.ReceiveMessage(server, inBuf);

When I step through telnet manually I get full whois data but I am not sure where this data is being stored in this code. Is there a byte array somewhere I am meant to access?

nterry commented 5 years ago

@GuerrillaCoder It's in the inBuf. The second parameter in ReceiveMessage is an out parameter.

nterry commented 4 years ago

@GuerrillaCoder Did you manage to get the data from the inBuf?

GuerrillaCoder commented 4 years ago

Hi @nterry I didn't try, when I couldn't get it to work I coded my own loop using .net socket library. If I re-visit the project I will give it a try.