The TCPSocket is just a pipe that you write bytes to; it doesn't handle the encoding at all. Additionally, the HTTPServer example isn't an HTTP-compliant server. All it does is accept requests (over HTTP) and then writes the requested file to the socket. It doesn't send the required HTTP response headers, etc.
A quick fix would be something like this:
Protected Sub ProcessHeaders(headers as string)
dim temp,cmd,param as string
dim bs as binaryStream
dim f as folderItem
// parse out the header data
temp = nthField(headers,chr(13),1)
cmd = nthField(temp," ",1)
param = nthField(temp," ",2)
if cmd = "GET" then// we got a get command
f = getHTTPFileFromPath(param)
if f = NIL OR f.exists = false then// could not find the file (404)
me.write "Error 404."
bs = BinaryStream.Open(f, False)
'FIX STARTS HERE
'This next line puts some basic HTTP headers into the 'responseheaders' string
Dim responseheaders As String = "HTTP/1.1 200 OK" + EndOfLine.Windows + "Content-Type: text/html; charset=UTF-8"
'This line writes the headers, two end-of-line markers, and then the actual content
me.write responseheaders + EndOfLine.Windows + EndOfLine.Windows + bs.read(bs.length)
Note the Content-Type header. This header specifies the datatype and encoding of the data being written to the socket.
As I said, however, the sample HTTP server is not a compliant HTTP server; it's merely for demonstration purposes. A much more robust HTTP implementation in RealBasic can be found here: https://github.com/bskrtich/RBHTTPServer