For this piece of code:
String content = String.Empty;
ListenerStateObject state = (ListenerStateObject)ar.AsyncState;
Socket handler = state.workSocket;
int bytesRead = handler.EndReceive(ar);
if (bytesRead > 0)
{
state.sb.Append(Encoding.UTF8.GetString(state.buffer, 0, bytesRead));
content = state.sb.ToString();
...
I’m geting ‘Ol?’ instead of ‘Olá’
What’s wrong with it?
Are you sure that the stream is actually utf-8 encoded? Try inspecting the raw bytes in the buffer before encoding (there should be 4) and see what the actual byte values are.