I created a .NET Core console application.
The code is not working when client request from wss, my client url is hosted on https url and has valid certificate
Here is the server code :
static void Main(string[] args)
{
serverSocket.Bind(new IPEndPoint(IPAddress.Any, 8122));
serverSocket.Listen(128);
serverSocket.BeginAccept(null, 0, OnAccept, null);
Console.Read();
}
Here is the OnAccept
method :
private static void OnAccept(IAsyncResult result)
{
byte[] buffer = new byte[1024];
Socket client = null;
string headerResponse = "";
if (serverSocket != null && serverSocket.IsBound)
{
client = serverSocket.EndAccept(result);
var i = client.Receive(buffer);
string browserSent = GetDecodedData(buffer, i);
Console.WriteLine("BrowserSent: " + browserSent);
headerResponse = (System.Text.Encoding.UTF8.GetString(buffer)).Substring(0, i);
// write received data to the console
}
}
Here is the javascript :
<script type="text/javascript">
//Test
var socket = new WebSocket('wss://<%=serverURL%>:8122');
var myVar;
socket.onopen = function (event) {
var obj = { action: "admin", clientID: document.getElementById('<%=hid_clientid.ClientID %>').value, userID: document.getElementById('<%=hid_userid.ClientID %>').value };
socket.send(JSON.stringify(obj));
//myVar = setInterval(function timeout() {
//}, 3000);
};
</script>