Squeak <> Amber communication using WebSocket (works)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Squeak <> Amber communication using WebSocket (works)

Jacob Wagner
http://zenchess.blogspot.com/2011/10/amber-client-to-squeak-image.html


 I have had success testing amber to squeak (and back) communication
using websocket.  This is after hours of failing to get socket.io and
nowJs to work with amber server.
WebSocket is a new protocol in HTML 5 and is supported on modern
browsers.  The channel is always open so you do not have to constantly
poll the server for updates.  The channel is also
bi-directional.

  Here is a post I made describing how I got it to work with WebClient
for squeak and stock amber.  Please note the pastebin link at top -
the code didn't format correctly in blogger.

There are some quirks such as having to send the "send:" message to
websocket at the same time as the other code (or it doesnt work).  But
once you do that you can send messages to the WebSocket object at your
leisure.

  Right now I am using squeak with Webclient but pharo 1.3 can run
Websockets through swazoo2 so you could use that as well I'm
assuming.

Happy smalltalking!
-Jacob Wagner
<zenchess@gmail.com>
Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Bernat Romagosa
Great, Jacob!

I'll take a look at it later, thanks for sharing :)

2011/10/24 Zenchess <[hidden email]>
http://zenchess.blogspot.com/2011/10/amber-client-to-squeak-image.html


 I have had success testing amber to squeak (and back) communication
using websocket.  This is after hours of failing to get socket.io and
nowJs to work with amber server.
WebSocket is a new protocol in HTML 5 and is supported on modern
browsers.  The channel is always open so you do not have to constantly
poll the server for updates.  The channel is also
bi-directional.

 Here is a post I made describing how I got it to work with WebClient
for squeak and stock amber.  Please note the pastebin link at top -
the code didn't format correctly in blogger.

There are some quirks such as having to send the "send:" message to
websocket at the same time as the other code (or it doesnt work).  But
once you do that you can send messages to the WebSocket object at your
leisure.

 Right now I am using squeak with Webclient but pharo 1.3 can run
Websockets through swazoo2 so you could use that as well I'm
assuming.

Happy smalltalking!
-Jacob Wagner



--
Bernat Romagosa.
Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Bernat Romagosa
Hi Jacob,

I tried to run your example but all I got is "ConnectionClosed: Connection closed while waiting for data." in my Pharo Transcript, among lots of extra gibberish.

It's weird because not even the chat example is working, any ideas on what's going on?

Cheers!

2011/10/24 Bernat Romagosa <[hidden email]>
Great, Jacob!

I'll take a look at it later, thanks for sharing :)

2011/10/24 Zenchess <[hidden email]>
http://zenchess.blogspot.com/2011/10/amber-client-to-squeak-image.html


 I have had success testing amber to squeak (and back) communication
using websocket.  This is after hours of failing to get socket.io and
nowJs to work with amber server.
WebSocket is a new protocol in HTML 5 and is supported on modern
browsers.  The channel is always open so you do not have to constantly
poll the server for updates.  The channel is also
bi-directional.

 Here is a post I made describing how I got it to work with WebClient
for squeak and stock amber.  Please note the pastebin link at top -
the code didn't format correctly in blogger.

There are some quirks such as having to send the "send:" message to
websocket at the same time as the other code (or it doesnt work).  But
once you do that you can send messages to the WebSocket object at your
leisure.

 Right now I am using squeak with Webclient but pharo 1.3 can run
Websockets through swazoo2 so you could use that as well I'm
assuming.

Happy smalltalking!
-Jacob Wagner



--
Bernat Romagosa.



--
Bernat Romagosa.
Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Amber Milan Eskridge
I use Socket.io and node.js with Amber both on server and client and it works pretty well.

On Tue, Oct 25, 2011 at 9:54 AM, Bernat Romagosa <[hidden email]> wrote:
Hi Jacob,

I tried to run your example but all I got is "ConnectionClosed: Connection closed while waiting for data." in my Pharo Transcript, among lots of extra gibberish.

It's weird because not even the chat example is working, any ideas on what's going on?

Cheers!


2011/10/24 Bernat Romagosa <[hidden email]>
Great, Jacob!

I'll take a look at it later, thanks for sharing :)

2011/10/24 Zenchess <[hidden email]>
http://zenchess.blogspot.com/2011/10/amber-client-to-squeak-image.html


 I have had success testing amber to squeak (and back) communication
using websocket.  This is after hours of failing to get socket.io and
nowJs to work with amber server.
WebSocket is a new protocol in HTML 5 and is supported on modern
browsers.  The channel is always open so you do not have to constantly
poll the server for updates.  The channel is also
bi-directional.

 Here is a post I made describing how I got it to work with WebClient
for squeak and stock amber.  Please note the pastebin link at top -
the code didn't format correctly in blogger.

There are some quirks such as having to send the "send:" message to
websocket at the same time as the other code (or it doesnt work).  But
once you do that you can send messages to the WebSocket object at your
leisure.

 Right now I am using squeak with Webclient but pharo 1.3 can run
Websockets through swazoo2 so you could use that as well I'm
assuming.

Happy smalltalking!
-Jacob Wagner



--
Bernat Romagosa.



--
Bernat Romagosa.

Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Jacob Wagner

Any chance you could whip up a quick  how-to on using socket.io with
amber?
<zenchess@gmail.com>
Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Jacob Wagner
In reply to this post by Bernat Romagosa
I think webclient websockets don't work in pharo for some reason.

<zenchess@gmail.com>
Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Bernat Romagosa
I have the same impression :)

I'm trying to get a little multiclient chat demo working based on laci's experiments, I think this would make an interesting example...

Cheers,

2011/10/26 Zenchess <[hidden email]>
I think webclient websockets don't work in pharo for some reason.




--
Bernat Romagosa.
Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Amber Milan Eskridge
Here's a rough-cut of using socket.io with Amber:

Install Node.js in the appropiate way for your plattform.

Install socket.io using npm.
If that fails, download it manually and set your node module path like so:
"export NODE_PATH=$NODE_PATH:/your/path/to/socket.io/"

Create a server-script in node.js for example by subclassing FileServer and create a start-method:
YourFileServer>>start
(httpServer := http createServer: [:request :response |
self handleRequest: request respondTo: response]) listen: self port.
self setupSocketIO.

Create a socket setup method:

YourFileServer>>setupSocketIO
| iopath |
        "Require with just the name did not work for me, I had to specify the path manually"
iopath := '/Network/Servers/Eskridge/Projects/Amber/amber/.node_modules/socket.io/index'.
        "Mount socket.io to the httpServer created in #start"
io := (self require: iopath) listen: httpServer.
        "Define the behaviour of the socket"
io sockets on: 'connection' on: [:socket|    "callback gives you the handle to the socket. you can store that for later"                         
        socket on: 'NewsPosted' do: [ :eventInfo | "specify the events you want to distribute here"
socket emit: 'RemoveCard' withData: eventInfo. "Here I just recast it"
].

On the client 
Insert into the head of your html: 
<script src="/socket.io/socket.io.js"></script>


Establish the connection & event-handling
ClientController>>establishConnection
self socket: (io connect: 'http://your-url-and-server:port:').
self socket on: 'NewsPosted' do: [:data | alert value: data]. "You can specify all the events you want to handle this way or write a method for it"

"convinience method for the specification of events to handle"
ClientController>>on: anEvent do: anUnaryBlock
self socket on: anEvent do: [:eventInfoString | anUnaryBlock value: (JSON parse: eventInfoString)] .

And send data:
ClientController>>postNews: jsonData
self socket emit: 'NewsPosted' with: jsonData.

Maybe I can extract the chat I wrote later, but that is not a priority right now for me.


On Wed, Oct 26, 2011 at 10:12 AM, Bernat Romagosa <[hidden email]> wrote:
I have the same impression :)

I'm trying to get a little multiclient chat demo working based on laci's experiments, I think this would make an interesting example...

Cheers,


2011/10/26 Zenchess <[hidden email]>
I think webclient websockets don't work in pharo for some reason.




--
Bernat Romagosa.

Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Jacob Wagner
  Thank you!  Without knowing about your post, I tried again to get
nowjs to work with amber, and this blog post
http://zenchess.blogspot.com/2011/10/ambernodeamber-using-nowjs.html
is the result of that.

  I will be investigating your method as well to see if I can improve
on it.

  Nowjs is a module that uses socket.io to make it really easy to do
multiuser stuff.  For example you can do something like
everyone.now.receiveMessage("Each client gets this message"); .  And
the client can call functions on the server easily as well.

  -Jacob
<zenchess@gmail.com>
Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Bernat Romagosa
In reply to this post by Amber Milan Eskridge
Hi Amber! You have the most convenient name in the community!

Are your examples hosted somewhere? I'd like to take a peek at your code.

Cheers,

2011/10/26 Amber Milan Eskridge <[hidden email]>
Here's a rough-cut of using socket.io with Amber:

Install Node.js in the appropiate way for your plattform.

Install socket.io using npm.
If that fails, download it manually and set your node module path like so:
"export NODE_PATH=$NODE_PATH:/your/path/to/socket.io/"

Create a server-script in node.js for example by subclassing FileServer and create a start-method:
YourFileServer>>start
(httpServer := http createServer: [:request :response |
self handleRequest: request respondTo: response]) listen: self port.
self setupSocketIO.

Create a socket setup method:

YourFileServer>>setupSocketIO
| iopath |
        "Require with just the name did not work for me, I had to specify the path manually"
iopath := '/Network/Servers/Eskridge/Projects/Amber/amber/.node_modules/socket.io/index'.
        "Mount socket.io to the httpServer created in #start"
io := (self require: iopath) listen: httpServer.
        "Define the behaviour of the socket"
io sockets on: 'connection' on: [:socket|    "callback gives you the handle to the socket. you can store that for later"                         
        socket on: 'NewsPosted' do: [ :eventInfo | "specify the events you want to distribute here"
socket emit: 'RemoveCard' withData: eventInfo. "Here I just recast it"
].

On the client 
Insert into the head of your html: 
<script src="/socket.io/socket.io.js"></script>


Establish the connection & event-handling
ClientController>>establishConnection
self socket: (io connect: 'http://your-url-and-server:port:').
self socket on: 'NewsPosted' do: [:data | alert value: data]. "You can specify all the events you want to handle this way or write a method for it"

"convinience method for the specification of events to handle"
ClientController>>on: anEvent do: anUnaryBlock
self socket on: anEvent do: [:eventInfoString | anUnaryBlock value: (JSON parse: eventInfoString)] .

And send data:
ClientController>>postNews: jsonData
self socket emit: 'NewsPosted' with: jsonData.

Maybe I can extract the chat I wrote later, but that is not a priority right now for me.


On Wed, Oct 26, 2011 at 10:12 AM, Bernat Romagosa <[hidden email]> wrote:
I have the same impression :)

I'm trying to get a little multiclient chat demo working based on laci's experiments, I think this would make an interesting example...

Cheers,


2011/10/26 Zenchess <[hidden email]>
I think webclient websockets don't work in pharo for some reason.




--
Bernat Romagosa.




--
Bernat Romagosa.
Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Amber Milan Eskridge
In reply to this post by Jacob Wagner
NowJS sounds very interessting. I'll investigate.

On Wed, Oct 26, 2011 at 12:18 PM, Zenchess <[hidden email]> wrote:
 Thank you!  Without knowing about your post, I tried again to get
nowjs to work with amber, and this blog post
http://zenchess.blogspot.com/2011/10/ambernodeamber-using-nowjs.html
is the result of that.

 I will be investigating your method as well to see if I can improve
on it.

 Nowjs is a module that uses socket.io to make it really easy to do
multiuser stuff.  For example you can do something like
everyone.now.receiveMessage("Each client gets this message"); .  And
the client can call functions on the server easily as well.

 -Jacob

Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Amber Milan Eskridge
In reply to this post by Bernat Romagosa
Are your examples hosted somewhere? I'd like to take a peek at your code.

No, I extracted the examples from code I work on that is more or less a private project. 
Reply | Threaded
Open this post in threaded view
|

Re: Squeak <> Amber communication using WebSocket (works)

Amber Milan Eskridge
In reply to this post by Amber Milan Eskridge
As far as I can tell, in order to call the methods of arbitrary objects you have to put them in the now object or write for everything functions. This seems to me not very object-oriented. In that regard, I like an Announcements / Event-based approach better.

On Wed, Oct 26, 2011 at 1:28 PM, Amber Milan Eskridge <[hidden email]> wrote:
NowJS sounds very interessting. I'll investigate.