|
|
Hi, a while back I tried using websockets to work with squeak, pharo
and amber, with some limited success. I can't remember exactly why I gave up on the idea, but for some reason it didn't work out for me. I posted on the newsgroup about my efforts. Well, I noticed a forum post from world.st in which WebClient and WebServer were updated for squeak to use more modern websocket protocols. I decided to try them again. I now have a fully functional multiplayer game demo coded in amber in client and squeak for server. Using this solution I don't think you need to host amber in any special way - you don't need to host it in node and you don't need to use the recent one click solution. Just serve your client files via apache or whatever, and have a running squeak image on the same domain (if it's not on the same domain it won't work because of cross site scripting security blocks on all major browsers). First off, let me say that if you try this - you're probably better off using squeak instead of pharo. The package WebClient is made for squeak, and I had trouble getting the pharo version to work in the past and recently as well. If you want to try to get it to work in pharo, you'll need to figure out how to install 'Installer' first, (I tried installing it and it crashed my image). To get this whole thing to work, get squeak and install the latest WebClient package (it supports websockets and comes with WebServer class as well). In amber no special libraries are necessary, at least on chrome. (It should work in firefox and other major browsers as well). Once you've got your squeak image running, it's a simple matter of using standard WebSocket object in amber/javascript and modifying the WebSocket class >> example method in squeak. In case you have problems getting started, here is my cheat sheet for useful methods on both sides: Amber: <socket = new WebSocket("ws://www.zenchess.com:4003/broadcast");>. ^^ modify the above code to point to your web domain and the port that WebSocket example is running on. <socket.onopen = function(){ alert("Socket has been opened!"); self._onOpen(); } >. ^^ There's the function you register with your socket object that gets called when the socket is opened for the first time. self._onOpen(); is javascript code that will call the onOpen method in the class that it is running from. This lets me write an onOpen method in complete smalltalk. I couldn't figure out how to convert the above javascript code into the smalltalk equivalent, so that is why I am using the < > 's . <socket.onmessage = function(msg){ data = msg.data;>. Hopefully the above code and explanation can help anyone that is looking for amber>regular smalltalk image communication. I know there are other solutions but websocket is actually a really good one, since it's 2-way and does not have to continuously poll to get updates. By the way there are some JSON convenience methods for decoding and encoding JSON in squeak in the WebUtils package of WebClient that came in handy as well. I've been coding a multiplayer turn based strategy game in Ludus/ Amber/Squeak and it's coming along nicely, I'll be sure to demo it here first. :P |
|
Nicolas Petton |
|
|
On 20/02/12 06:55, Zenchess wrote:
Did you know you can that in Smalltalk: > Amber: > > <socket = new WebSocket("ws://www.zenchess.com:4003/broadcast");>. socket := WebSocket new value: 'ws://www.zenchess.com:4003/broadcast'. > > ^^ modify the above code to point to your web domain and the port that > WebSocket example is running on. > > <socket.onopen = function(){ > alert("Socket has been opened!"); > self._onOpen(); > }>. > socket onopen: [ window alert: 'socket open'. self onOpen] > > <socket.onmessage = function(msg){ > > data = msg.data;>. socket onmessage: [:msg | data := mdg data] Cheers, Nico -- Nicolas Petton http://nicolas-petton.fr |
|
Bernat Romagosa |
|
|
Cool stuff! Welcome back!
Can we get a URL to your demo app to take a look at it? Cheers,
2012/2/20 Nicolas Petton <[hidden email]> On 20/02/12 06:55, Zenchess wrote: Bernat Romagosa. |
|
|
In reply to this post by Nicolas Petton
Hi Nicolas, I tried your version of the code, and got this:
"function WebSocket() { [native code] } does not understand #new" On Feb 20, 3:50 am, Nicolas Petton <[hidden email]> wrote: > On 20/02/12 06:55, Zenchess wrote: > > Did you know you can that in Smalltalk: > > > Amber: > > > <socket = new WebSocket("ws://www.zenchess.com:4003/broadcast");>. > > socket := WebSocket new value: 'ws://www.zenchess.com:4003/broadcast'. > > > > > ^^ modify the above code to point to your web domain and the port that > > WebSocket example is running on. > > > <socket.onopen = function(){ > > alert("Socket has been opened!"); > > self._onOpen(); > > }>. > > socket onopen: [ > window alert: 'socket open'. > self onOpen] > > > > > <socket.onmessage = function(msg){ > > > data = msg.data;>. > > socket onmessage: [:msg | data := mdg data] > > Cheers, > Nico > > -- > Nicolas Pettonhttp://nicolas-petton.fr |
|
|
In reply to this post by Bernat Romagosa
I'm almost finished making the game, so I'd like to finish that
first. > Cool stuff! Welcome back! > > Can we get a URL to your demo app to take a look at it? > > Cheers, > |
|
Nicolas Petton |
|
|
In reply to this post by Zenchess
On 22/02/12 09:45, Zenchess wrote:
> Hi Nicolas, I tried your version of the code, and got this: > > "function WebSocket() { [native code] } does not understand #new" Yeah, there's an error in the code I wrote. It should be: socket := WebSocket newValue: 'ws://www.zenchess.com:4003/broadcast' But anyway WebSocket isn't a normal function, so it doesn't seem to work in this particular case :/ Cheers, Nico > > > On Feb 20, 3:50 am, Nicolas Petton<[hidden email]> wrote: >> On 20/02/12 06:55, Zenchess wrote: >> >> Did you know you can that in Smalltalk: >> >>> Amber: >> >>> <socket = new WebSocket("ws://www.zenchess.com:4003/broadcast");>. >> >> socket := WebSocket new value: 'ws://www.zenchess.com:4003/broadcast'. >> >> >> >>> ^^ modify the above code to point to your web domain and the port that >>> WebSocket example is running on. >> >>> <socket.onopen = function(){ >>> alert("Socket has been opened!"); >>> self._onOpen(); >>> }>. >> >> socket onopen: [ >> window alert: 'socket open'. >> self onOpen] >> >> >> >>> <socket.onmessage = function(msg){ >> >>> data = msg.data;>. >> >> socket onmessage: [:msg | data := mdg data] >> >> Cheers, >> Nico >> >> -- >> Nicolas Pettonhttp://nicolas-petton.fr -- Nicolas Petton http://nicolas-petton.fr |
|
Amber Milan Eskridge |
|
|
In reply to this post by Zenchess
Congratulations. Looking forward to play a game.
On Wed, Feb 22, 2012 at 9:46 AM, Zenchess <[hidden email]> wrote: I'm almost finished making the game, so I'd like to finish that |
|
Ankh'nAton |
|
|
In reply to this post by Nicolas Petton
On 22 Feb., 11:38, Nicolas Petton <[hidden email]> wrote: > On 22/02/12 09:45, Zenchess wrote: > > > Hi Nicolas, I tried your version of the code, and got this: > > > "function WebSocket() { [native code] } does not understand #new" > > Yeah, there's an error in the code I wrote. It should be: > socket := WebSocket newValue: 'ws://www.zenchess.com:4003/broadcast' > > But anyway WebSocket isn't a normal function, so it doesn't seem to work > in this particular case :/ > I get an error on Chrome 12.0 and FF 10.0 saying: function WebSocket() { [native code] } does not understand #newValue:" Regards... |
| Powered by Nabble | See how NAML generates this page |