[Solved] TSocketStream.Write/WriteAnsiString -- Missing and extra chars lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Trenatos · 2018-11-27 03:32 I'm going insane. I'm trying to write to a TSocketStream, a response to a webbrowser request (Testing with curl) I can't figure out how to send what I want to send.. If I use WriteAnsiString(res) I get an extra random character in the beginning Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i res: AnsiString; res := 'HTTP/1.1 200 OK'; Data.WriteAnsiString(res);  And if I use Data.Write(tmp, 15) it eats the first character. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i tmp: Array[0..14] of Char;res: AnsiString; res := 'HTTP/1.1 200 OK';tmp := res; Data.Write(tmp[1], 15);  What am I missing? ---------------------------------------------------------------------- bytebites · 2018-11-27 04:14 WriteAnsiString writes length and the string itself. Maybe you need Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Data.Write(res[1],length(res)); ---------------------------------------------------------------------- Thaddy · 2018-11-27 09:00 Indeed! And the character is not random...... ( You can also cast to a PChar) A stream is a stream. EVERY byte is important. ---------------------------------------------------------------------- Trenatos · 2018-11-27 12:43 I wasn't going insane, but I did have a copy pasta problem.. I grabbed a reply string from a C example, including \n, I switched to sLineBreak and with WriteAnsiString() the browser now shows data with no error. So I'm guessing that with Write() I have to add the first byte manually, it "disappeared" because it was treated as a size marker. WriteAnsiString() worked fine, so I should have just used linebreaks properly, and the "extra" character is the size marker but it shows up as an ascii character with the CURL output. On to the next challenge!  Thanks guys