mastodon.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
The original server operated by the Mastodon gGmbH non-profit

Administered by:

Server stats:

360K
active users

loganer

to send a file over a socket connection do I just read the file from the disk and send them as raw bytes or is there something special i need to do?

for example, if I have a TestImage.png in my 'web root' directory and a browser request the /TestImage.png , do I just read the file byte for byte into an array and then just send that to be browser?

@loganer In general, yes.

If you need to adhere to a protocol, then you should look up that protocol.

You mention a browser, so I assume you're using HTTP. If so, you need to send a well-formed HTTP response, including headers. Most important are Content-Size and Content-Type, which tell the browser the number of bytes to read and the file's MIME type respectively. After terminating the headers with "\r\n\r\n", you can send the raw bytes from your PNG file.

You should also check endianness.

@dragon0 ya, I'm currently working on a function to generate the http header for the reply.

I just wanted to make sure I didn't have to do anything special for images compared to text as I can't exactly copy/paste an image into a text editor to compare the differences.