System.AggregateException in TCP requests
I'm trying to make my own version of HTTP, however I get the following exception whenever I try to communicate between my client and server: System.AggregateException: One or more errors occurred. (Unable to read data from the transport connection: An established connection was aborted by the software in your host machine..)
41 Replies
I've attached my library, the error is on line 58 of WtpClient.cs
please $paste the relevant code @LocalDutchBoi โ๐ณ๐, people are unlikely to download zips
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
Never used the bot, give me a sec
$paste
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
BlazeBin - bpkvkakmsluc
A tool for sharing your source code with the world!
It uses a self-made testing lib, so it likely won't run on your own machine, the testing lib is in the zip
for one this is wrong
every time the loop hits ReadAsync
it may return a different number
so u need to sum it for the total bytes u've read
small nit, you don't need
GC.SuppressFinalize
also, I see await using var stream = client.GetStream();
in WtpServer.HandleClientAsync
, which I think might be closing the connection after the initial message handle
Is that what you want?also you're encoding with u8 but reading ASCII
on line 38 on the first tab of the paste.mod link above
althou it might work for some strings not good to mix encoding like that
yes disposing a stream would close the connection.
the whole reading back of the response in the client is wrong.
as mentioned, you are not keeping track of how many bytes u have read in total, and u are also overwriting the previously received chunk.
basically if u get a 16384 bytes request, in best case u get the last 8192 bytes, in worst case u get the last 1 byte.
HTTP messages (both requests and responses) can often be really long so u dont want to read them into memory all at once.
you would streamingly read the next bytes to build some kind of object that contains the headers and then some stream object that consists of the body by parsing the incoming data.
the buffering of data is really annoying here because HTTP isnt a length+value protocol, so u dont really know when u can stop reading the headers and maybe even have read part of the message body.
for that data buffering at least there is System.IO.Pipelines (i would recommend reading the article as a whole, it has through out some important pieces of information)
In this case it returns the same byte[]
using only disposes it after it exits the scope, no?
I'll try doing it without the
await using
part
yeah ik i try to keep it consistent but my ide whines
i'll fix the memory reading part, it was just a quick thing to testthe thing is, it goes out of scope as soon as it finishes the first message
because it does not have a loop to receive more messages
yeah because then it instantly returns
the server side part i couldnt check, i dont download arbitrary zip files
thus closing the connection
removed
await using
, now it doesnt error anymore but it hangs
probably an issue with my testing framework
theres a server file in the paste i senteither way
you have no logic in your server
that will care for more than the first message it gets
i started it yesterday night
i do
no
that only cares for the connection
i think im blind โคด๏ธ is the only source i see
it takes the accepted client and calls that method
that method does not do anything else besides running once
oh in that way
ooh
that's a design thing
sure
didnt know that has tabs nowadays ๐ im sorry
it's a like http not sockets
always had
im sure it is that is why cotton asked u how you wanted it work
if u wanted to get only 1 request at a time of ir u wanted it to return multiple
i just want 1 request, 1 response
anyway, what u want to do is you want to signal you're closing the socket after u send your response
might update WtpClient so it can reconnect to different servers
wait for the other part to reply
and then close
fixed that now
that
HandleClientAsync
closes the connection after handling it, is okay and expected.
its just that it should handle the whole thing, not just one message (eg, if u want to implement keep-alive, it would start to handle multiple requests, timeouts, etc)i just want 1 message
i'll implement things like "received" and stuff
this fixed the error btw
thanks leowest, leopard and cap5lut
even if its just accet-receive-response-close, u would sill do all of that in that method ;p
leopard actually pointed that out not me ๐ but you're welcome
that method is more or less ur main method for each connection