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.
-
AuthorPosts
-
December 4, 2017 at 3:00 am #12087
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.December 4, 2017 at 3:08 am #12088Is 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.
December 4, 2017 at 3:22 am #12091I 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.December 4, 2017 at 3:39 am #12093So 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.
December 4, 2017 at 3:43 am #12094Hehe alright, I’ll investigate a bit!
December 4, 2017 at 8:22 am #12105I 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!
December 4, 2017 at 8:29 am #12107Just 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.
December 4, 2017 at 7:59 pm #12113Possible starting point:
http://demos.kaazing.com/echo/
There should be a bunch of similar ‘test’ servers around on the internet too…
December 4, 2017 at 8:07 pm #12114The 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?
December 4, 2017 at 8:26 pm #12115But 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!
December 4, 2017 at 8:31 pm #12116Well 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
Monkey1If socketnever 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.December 4, 2017 at 8:37 pm #12117Copy 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?
December 4, 2017 at 8:55 pm #12118Sorry if I’m frustrating you Mark heh.
Thanks for all the help! <3But 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 .htmlXHTML123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051<title>WebSocket Chat Test</title><meta charset=UTF-8 /><script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script><br /><form name="chat" /><textarea cols="100" rows="20" id="chat"></textarea><br /><input type="text" id="text" /><input type="submit" value="Send"></form><script>$(function(){var UserName = prompt("Username:", "");var ws// Let us open a web socketif(window.WebSocket){ws=new WebSocket("ws://demos.kaazing.com/echo");}else{ws=new MozWebSocket("ws://demos.kaazing.com/echo");}ws.onopen = function(){// Web Socket is connected, send data using send()ws.send("name"+String.fromCharCode(0)+UserName); // Say Hello...};ws.onmessage = function (evt){var $chat = $("#chat");var txt = $chat.val();$chat.val(txt+evt.data+"\n");};ws.onclose = function(){var $chat = $("#chat");var txt = $chat.val();$chat.val(txt+"Close\n");};$('form').submit(function(e){var text = $('#text').val();$('#text').val('');var $chat = $('#chat');ws.send(text);$chat.val($chat.val()+UserName+": "+text+"\n");e.preventDefault();});});</script>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.December 5, 2017 at 1:07 am #12120Thanks 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.
December 5, 2017 at 1:12 am #12121I 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. -
AuthorPosts
You must be logged in to reply to this topic.