Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket IO client application not connecting c# based server #3607

Closed
AmitDKabade opened this issue Jun 5, 2020 · 1 comment
Closed

Socket IO client application not connecting c# based server #3607

AmitDKabade opened this issue Jun 5, 2020 · 1 comment

Comments

@AmitDKabade
Copy link

AmitDKabade commented Jun 5, 2020

Hi, I am facing issue to connect SocketIO to c# based server.
if I am using pure WebSocket it connects to the server but from socketio it not connecting.
I have attached my client side code as well as server side alongwith the errror trace anybdoy can please help me on the same
SERVER CODE :
var szData = new ASCIIEncoding().GetString(e.Buffer, 0, count).Replace("\0", "");
if (Regex.IsMatch(szData, "^GET", RegexOptions.IgnoreCase))
{
string swk = Regex.Match(szData, "Sec-WebSocket-Key: (.)").Groups[1].Value.Trim();
string path = Regex.Match(szData, "GET (.
)").Groups[1].Value.Trim();
string host = Regex.Match(szData, "Host: (.)").Groups[1].Value.Trim();
string origin = Regex.Match(szData, "Origin: (.
)").Groups[1].Value.Trim();
string swka = swk + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
byte[] swkaSha1 = System.Security.Cryptography.SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(swka));
string swkaSha1Base64 = Convert.ToBase64String(swkaSha1);
string request = "GET " + path + " \r\n" +
"Upgrade: WebSocket\r\n" +
"Connection: Upgrade\r\n" +
"Host: " + host + "\r\n" +
"Origin: " + origin + "\r\n" +
"Sec-WebSocket-Accept: " + swkaSha1Base64 + "\r\n\r\n";

                                byte[] sendBuffer = Encoding.UTF8.GetBytes(request);

                                byte[] response = Encoding.UTF8.GetBytes(
                "HTTP/1.1 101 Switching Protocols\r\n" +
                "Connection: Upgrade\r\n" +
                "Upgrade: websocket\r\n" +
                "Host: " + host + "\r\n" +
                "Origin: " + origin + "\r\n" +
                "Sec-WebSocket-Accept: " + swkaSha1Base64 + "\r\n\r\n");

                                ObjPlayerSocket.Send(response);

CLIENT CODE:
var sioclient = io.connect('ws://192.168.0.2:9250/', {upgrade: false, transports: ['websocket'],reconnectionDelay:5000});
this._sioClient = sioclient;
//if you need to track multiple sockets it is best to store them with tags in your own array for now
this.tag = sioclient.tag = "Test Client";

    //register event callbacks
    //this is an example of a handler declared inline
    sioclient.on("connect", function () {
        console.log("Connected");
        // Send message after connection
        self._sioClient.send("Hello Socket.IO!");
    });

    sioclient.on("error", function (event) {
        console.log("onerror");
        console.log(event.code);
        // Send message after connection
        //self._sioClient.send("Hello Socket.IO!");
    });

ws://192.168.0.2:9250/
socket-io.js:1068 parse ws://192.168.0.2:9250/
socket-io.js:63 new io instance for ws://192.168.0.2:9250/
socket-io.js:299 readyState closed
socket-io.js:302 opening ws://192.168.0.2:9250/
socket-io.js:1667 creating transport "websocket"
socket-io.js:1758 setting transport websocket
socket-io.js:334 connect attempt will timeout after 20000
socket-io.js:299 readyState opening
socket-io.js:338 connect attempt timed out after 20000
socket-io.js:2183 socket close with reason: "forced close"
socket-io.js:2128 socket closing - telling transport to close
socket-io.js:317 connect_error
assets\Utility\AsyncSocket.ts:53 timeout
socket-io.js:555 will wait 3847ms before reconnect attempt
socket-io.js:561 attempting reconnect
assets\Utility\AsyncSocket.ts:70 reconnecting
socket-io.js:299 readyState closed
socket-io.js:302 opening ws://192.168.0.2:9250/
socket-io.js:1667 creating transport "websocket"
socket-io.js:1758 setting transport websocket
socket-io.js:334 connect attempt will timeout after 20000

@darrachequesne
Copy link
Member

Closed due to inactivity, please reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants