I have a C# app that implement a server ,I want this app to be able to get messages from the browser. how can I send tcp messages using javascript that c# can read? (obviously I can change the c# code and the javascript/angular code)
UPDATE - this is the c# code
private static TcpListener server;
static void Main(string[] args)
{
server = new TcpListener(IPAddress.Parse("127.0.0.1"), 476);
server.Start();
TcpClient client = server.AcceptTcpClient();
Console.WriteLine("accept spcket");
try
{
NetworkStream stream = client.GetStream();
//StreamReader read = new StreamReader(stream);
//Console.WriteLine(read.Read());
Byte[] b = new Byte[client.Available];
stream.Read(b, 0, b.Length);
string data = Encoding.UTF8.GetString(b);
Console.WriteLine(data);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
and this is the javascript code
function send() {
let s = new WebSocket("ws://localhost:476");
alert("WebSocket is supported by your Browser!");
s.onopen = function () {
s.send("my data");
alert("sent");
}
how do I get the body of the messages in c#?