Emscripten sockets

About Monkey 2 Forums Monkey 2 Programming Help Emscripten sockets

This topic contains 22 replies, has 3 voices, and was last updated by  DruggedBunny 1 year, 4 months ago.

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #12087

    Hezkore
    Participant

    I was under the impression that Emscripten supported the ‘Socket’ class, but I’ve always received the error “-1”.
    DruggedBunny posted this example, and using it I once again tested Emscripten and got error “-1” using sockets.

    So I guess my code wasn’t the problem, Emscripten really doesn’t support sockets(?)
    (something to add to the docs perhaps?)

    Is there ANY way I can send and receive data over the internet using Emscripten?
    I’ll work with whatever, as long as I can just send and receive some text.
    And I mean as a client, the server would be written in something else.

    #12088

    Mark Sibly
    Keymaster

    Is there ANY way I can send and receive data over the internet using Emscripten?

    You will need to set up a server that handles the websocket protocol I believe. I have no idea how to to this myself, but according to this it may be possible to do in monkey2:

    https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers

    It doesn’t look *that* painful, although I wont be attempting myself anytime soon sorry. And getting it hosted is another issue altogether if you don’t want to run the host yourself. But if you do get something going I’d be happy to help if I can.

    #12091

    Hezkore
    Participant

    I did write a websockets module for BMax, but as soon as I connect to.. well anything using Emscripten in M2 I receive the error “-1”
    So I don’t even know where to begin.

    #12093

    Mark Sibly
    Keymaster

    So I don’t even know where to begin.

    Welcome to my world!

    Perhaps try and get a plain WebSocket javascript test app working with your server first? This would probably be my approach – make sure server is working before trying to get clients working, as at this point it’s not even known whether monkey2 sockets work with emscripten. I’d actually be surprised if there’s not some tinkering required, as there has been on EVERY os so far.

    #12094

    Hezkore
    Participant

    Hehe alright, I’ll investigate a bit!

    #12105

    DruggedBunny
    Participant

    I did the very beginnings of a WebSockets server in BlitzMax, though I think it only handled the initial negotation (can’t test right now). Might point someone in the right direction…

    Won’t fill the thread with Max code!

    https://pastebin.com/YNMfwBB7

    #12107

    DruggedBunny
    Participant

    Just remembered Brucey wrapped libwebsockets for BlitzMax, too… might be something that could be adapted (on Github under bah.mod I think). Also believe skidracer’s dom module for mx1 had websockets stuff in it.

    #12113

    Mark Sibly
    Keymaster

    Possible starting point:

    http://demos.kaazing.com/echo/

    There should be a bunch of similar ‘test’ servers around on the internet too…

    #12114

    Hezkore
    Participant

    The problem is that as soon as I connect to my WebSocket server, that’s worked with a lot of other WebSocket apps, M2 just spits out -1.

    So even if I do follow the standards for WebSocket, I wouldn’t be able to actually connect to any of the servers.

    Or is this just me having that problem?

    #12115

    Mark Sibly
    Keymaster

    But what exactly do you expect me to do with ‘it spits out -1’?!?

    Please post a test app, explain what it *should* do, explain how to reproduce results, prove it’s not a server issue because of xyz etc (eg: ‘it works with this little js app’) and so on.

    In general, please provide as much information as possible – just going ‘it doesn’t work’ is no help at all!

    #12116

    Hezkore
    Participant

    Well as I said in my first post, DruggedBunny made an example which shows the error in Emscripten.

    Copy the example code from above: http://monkeycoder.co.nz/forums/topic/simple-http-1-1-web-page-download/

    Compile using Emscripten.

    The line

    never returns True, and “-1” is printed to the console for some reason.

    Doesn’t matter what server you try to connect to, WebSocket server or not, same result every time.

    So even if I were to respond to the WebSocket standards, there’s no way to actually connect to any form of server.
    Monkey 2 literally just prints “-1” whenever you try to connect to a server when compiled to Emscripten.

    #12117

    Mark Sibly
    Keymaster

     

    Copy the example code from above: http://monkeycoder.co.nz/forums/topic/simple-http-1-1-web-page-download/

    But that doesn’t even connect to websocket server so I’m not surprised it doesn’t work! Is it supposed to?

    Can you show an example of a js or other app successfully connecting to this (or any!) websocket server?

    Can you then show an example of an monkey2 app unsuccessfully attempting to do the same thing?

    #12118

    Hezkore
    Participant

    Sorry if I’m frustrating you Mark heh.
    Thanks for all the help! <3

    But that doesn’t even connect to websocket server so I’m not surprised it doesn’t work! Is it supposed to?

    I believe it should still connect, yes.
    But either way, you posted an echo WebSocket test client link before which connects to “ws://demos.kaazing.com/echo”
    So you could give the M2 example code a go using that echo server.
    (Doesn’t work -1 error)

    Can you show an example of a js or other app successfully connecting to this (or any!) websocket server?

    Once again, the link you posted is a client that can successfully connect to “ws://demos.kaazing.com/echo”
    But here’s an old chat app I’ve made to connect to the same demo echo server, and it works.
    Save as .html

    Can you then show an example of an monkey2 app unsuccessfully attempting to do the same thing?

    http://monkeycoder.co.nz/forums/topic/simple-http-1-1-web-page-download/
    Change address to the “ws://demos.kaazing.com/echo” echo test server.

    #12120

    Mark Sibly
    Keymaster

    Thanks for the sample code, it at least gives me a starting point.

    I guess you should be able to at least connect with http, but I doubt you’ll be able to do a full http GET. But I don’t honestly know how any of this stuff really works as yet so who knows?

    Will have a closer look when I get some free time, although I don’t quite know that’ll be right now.

    #12121

    Hezkore
    Participant

    I guess you should be able to at least connect with http, but I doubt you’ll be able to do a full http GET

    Exactly. 🙂
    The handshake will be all wrong, but a connection should be made.

    Will have a closer look when I get some free time, although I don’t quite know that’ll be right now.

    Alright, thanks Mark!
    I’m much more interested in the “secret project” anyways, it’s something I’ve wanted to experiment, so it’ll keep me busy while Emscripten Sockets don’t work heh.

Viewing 15 posts - 1 through 15 (of 23 total)

You must be logged in to reply to this topic.