locked
How do you send a message with WebSocket that targets Socket.IO?

    Question

  • Hi all,

    I've managed to connect to the websocket of a webserver that uses Socket.IO for chat between users on the website.

    Basically, the message type is "chat" with "recipient" and "message".

    To do this in java, with the Socket.IO client it would be as simple as using io.emit chat with a json object with recipient and message. But for some reason i get error 77 & 88 from the WebSocket server with a Connection Closed code 1000 (Without reason specified) when I try to do the following:

    var jsonMessage = new JSONClasses.Chat {message = message, recipient = recipient};
    
    var jsonString = JsonConvert.SerializeObject(jsonMessage);
    
    WebSocketWriter.WriteString("\"chat\"," + jsonString);
    var result = await WebSocketWriter.StoreAsync();

    Does anyone have any idea on how to correctly send the message using MessageWebSocket & DataWriter to Socket.IO?

    Edit: Here is the Encoder function for Socket.IO. https://github.com/Automattic/socket.io-parser/blob/master/index.js

    I have no idea what they are doing here. My JS skill is pretty much non-existant.
    • Edited by Cato L Tuesday, September 23, 2014 4:10 PM Added link to the Socket.io encoder/parser
    Tuesday, September 23, 2014 2:51 PM

All replies

  • I'm really confused - is this a JavaScript issue or a C# issue?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, September 24, 2014 12:20 PM
    Moderator
  • Sorry Matt. This is a C# issue. But the linked Java Script library should provide some insight as to how the message should be formatted to allow for a successful send, but it eludes me as of now.

    Wednesday, September 24, 2014 12:34 PM
  • This is all third-party as far as I can tell. You might want to ask on a forum that supports that technology.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, September 24, 2014 1:27 PM
    Moderator