0

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>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • What isn't working about it? Is it throwing an error? Not calling the function? Etc. – Selthien Jun 26 '21 at 05:39
  • WebSocket connection to 'wss://<>:8122' failed – tejas dhimmar Jun 26 '21 at 05:47
  • Could it be your main code is using ipaddress.any but your connection to a specific url? – Selthien Jun 26 '21 at 05:53
  • I used my hosting address not ip, i use specific url. i counld not get any data in buffer when call socket. i get 517 in var i at this line `var i = client.Receive(buffer);` – tejas dhimmar Jun 26 '21 at 06:23
  • You may be having issues with the linux operating system. The error 517 may be coming from the Android Shell. See following : https://stackoverflow.com/questions/34100047/what-does-unknown-error-517-mean-in-android-shell – jdweng Jun 26 '21 at 08:17

0 Answers0