So I am trying to setup a client websocket in a Javascript file talking to a server written in C#.
Client:
var socket = new WebSocket("ws://localhost:11000");
function barf() {
socket.send('asdf');
}
socket.onmessage = function(e){
console.log(e.data);
};
Server:
IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
IPAddress ipAddress = ipHostInfo.AddressList[1];
TcpListener listener = new TcpListener(ipAddress, 11000);
try
{
listener.Start();
TcpClient client = listener.AcceptTcpClient();
message = client.GetStream();
int i = message.Read(bytes);
string data = Encoding.ASCII.GetString(bytes, 0, i);
string key = new System.Text.RegularExpressions.Regex("Sec-WebSocket-Key: (.*)").Match(data).Groups[1].Value.Trim();
Byte[] response = GetHandshakeResponse(key);
message.Write(response, 0, response.Length);
bytes = new Byte[1024];
i = message.Read(bytes);
Console.WriteLine(Encoding.ASCII.GetString(bytes));
}
The issue is that when I call the function 'barf' in my Javascript file, the server spits out a different message each time as if it were being encrypted. I have tried using different encodings and I can't seem to end up with exactly 'asdf' on the server. Does anyone have any insight? Thanks!