nil error - Socket.io JObject

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

nil error - Socket.io JObject

xekoukou
I am trying to use socket.io with amber. 
http://socket.io/#how-to-use

I can pass messages to the javascript object io in the WorkSpace and it will execute nicely. When I inspect io, i see that its name is nil but except from that I can see its values. 

Now when I try to pass messages to io inside a smalltalk object, I get nil doesnt understand specific method. The debugger sees it as nil.

What should i do?

Here is the code. 

You need the socket.io module.

npm install socket.io.

If you have time: 

Try creating a new IOClient object. It will try to connect.

--

Sincerely yours, 
     Apostolis Xekoukoulotakis


index.html (874 bytes) Download Attachment
SocketIOClient.st (2K) Download Attachment
SocketIOClientLogic.st (746 bytes) Download Attachment
SocketIOClient.js (7K) Download Attachment
SocketIOClientLogic.js (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: nil error - Socket.io JObject

Jochem
Hi Apostolis,

What I did, as an example:

  s := io connect: '<a href="http://localhost:80'">http://localhost:80'.
  s on: 'getPosted' do: [:data | self showMessage: data].

And do not assign io as a variable. As io is already defined in
socketio javascript (as you already saw in the workspace)

Hope that helps.
Jochem


On 20 jun, 18:36, Apostolis Xekoukoulotakis <[hidden email]>
wrote:

> I am trying to use socket.io with amber.http://socket.io/#how-to-use
>
> I can pass messages to the javascript object io in the WorkSpace and it
> will execute nicely. When I inspect io, i see that its name is nil but
> except from that I can see its values.
>
> Now when I try to pass messages to io inside a smalltalk object, I get nil
> doesnt understand specific method. The debugger sees it as nil.
>
> What should i do?
>
> Here is the code.
>
> You need the socket.io module.
>
> npm install socket.io.
>
> If you have time:
>
> Try creating a new IOClient object. It will try to connect.
>
> --
>
> Sincerely yours,
>
>      Apostolis Xekoukoulotakis
>
>  index.html
> < 1 KWeergevenDownloaden
>
>  SocketIOClient.st
> 2KWeergevenDownloaden
>
>  SocketIOClientLogic.st
> < 1 KWeergevenDownloaden
>
>  SocketIOClient.js
> 7KWeergevenDownloaden
>
>  SocketIOClientLogic.js
> 2KWeergevenDownloaden
Reply | Threaded
Open this post in threaded view
|

Re: nil error - Socket.io JObject

xekoukou
It would be nice if there was a tutorial for us smalltalkers that dont know javascript how to use the existent javascript libraries.

On the server side, I didnt have any problems. The reason for that is that I used 'require' to load the socket.io javascript. Then everything worked like a charm.

On the client side, it seems that loading the javascript outside of the smalltalk class creates problems. And since having a global object would never happen in smalltalk, I dont know how to fix it.

Jochem, can you pass s on a smalltalk object of a different class without a problem? I noticed that i cannot transfer the socket to the SocketClient. Maybe I am doing something wrong.

thanks for your help by the way..


Reply | Threaded
Open this post in threaded view
|

Re: nil error - Socket.io JObject

Jochem
Hi Apostolis,

Here is just an example for socket.io on the client :
Index.html
<html>
<head>
<title>My Project</title>
<script src="../../js/amber.js" type="text/javascript"></script>
<script src="../../js/socket/dist/socket.io.js" type="text/
javascript"></script>
</head>
<body>
<script type="text/javascript">
        loadAmber({
                files: ['myproject.js'],
                prefix: 'examples/myproject/js',
                ready: function() {  smalltalk.MyProject._open(),
smalltalk.Browser._open();;

                }});
</script>
</body>
</html>

Here's the Amber source (.st file)

Smalltalk current createPackage: 'myproject' properties: #{}!
Widget subclass: #MyProject
        instanceVariableNames: 'socket'
        package: 'myproject'!

!MyProject methodsFor: 'not yet classified'!

doit
    socket emit: 'doPosted' with: 'just  a string'.
!

establishConnection
      socket := io connect: '<a href="http://localhost:80'">http://localhost:80'.
      socket on: 'receivePosted' do: [:data | self showMessage:
data.].
!

getit
    socket emit: 'getPosted' with: ' '.
!

renderOn: html
        html div
                with: [ html button class: 'btn';
                            with: 'Connect'; id: 'bc';
                        onClick: [ self establishConnection]];
               with: [ html button class: 'btn';
                            with: 'Emit to socket'; id: 'bdoit';
                        onClick: [ self doit]];
               with: [ html button class: 'btn';
                            with: 'get socket'; id: 'bget';
                        onClick: [ self getit]].
!

showMessage: aString
        | q|
q := 'body' asJQuery.
q append: '<p>' , aString, '</p>'.
! !

!MyProject class methodsFor: 'not yet classified'!

open
        self new appendToJQuery: 'body' asJQuery.
! !

Regards,
Jochem

On 21 jun, 22:44, Apostolis Xekoukoulotakis <[hidden email]>
wrote:

> It would be nice if there was a tutorial for us smalltalkers that dont know
> javascript how to use the existent javascript libraries.
>
> On the server side, I didnt have any problems. The reason for that is that
> I used 'require' to load the socket.io javascript. Then everything worked
> like a charm.
>
> On the client side, it seems that loading the javascript outside of the
> smalltalk class creates problems. And since having a global object would
> never happen in smalltalk, I dont know how to fix it.
>
> Jochem, can you pass s on a smalltalk object of a different class without a
> problem? I noticed that i cannot transfer the socket to the SocketClient.
> Maybe I am doing something wrong.
>
> thanks for your help by the way..
Reply | Threaded
Open this post in threaded view
|

Re: nil error - Socket.io JObject

Jochem
To make it complete, I have added the Nodejs code, also with a simple
Redis call
What I did to test socket.io is to have one nodejs server running on
port 4000 using the standard server for loading Amber, and another
nodejs server on port 80 to play with socket.io and redis.

start
        http := require value: 'http'.
        redis := require value: 'redis'.

        client := redis createClient.


     (httpServer := http createServer: [:request :response |
        self handleRequest: request respondTo: response]) listen:
'80'.

    io := (require value: 'socket.io') listen: httpServer.
     console log: 'io started'.
     io sockets on: 'connection' do:
        [:socket| socket on: 'doPosted' do:
                     [ :data | client set: 'key' with: data do:
                         [:err :reply |console log: reply]].
                  socket on: 'getPosted' do:
                     [ :data | client get: 'key' do:
                         [:err :reply |socket emit: 'receivePosted'
withData: reply.
                            console log: reply]]].

I am just playing with socket.io and redis, so I do not have a full
application running...

Jochem

On 22 jun, 21:28, Jochem <[hidden email]> wrote:

> Hi Apostolis,
>
> Here is just an example for socket.io on the client :
> Index.html
> <html>
> <head>
> <title>My Project</title>
> <script src="../../js/amber.js" type="text/javascript"></script>
> <script src="../../js/socket/dist/socket.io.js" type="text/
> javascript"></script>
> </head>
> <body>
> <script type="text/javascript">
>         loadAmber({
>                 files: ['myproject.js'],
>                 prefix: 'examples/myproject/js',
>                 ready: function() {  smalltalk.MyProject._open(),
> smalltalk.Browser._open();;
>
>                 }});
> </script>
> </body>
> </html>
>
> Here's the Amber source (.st file)
>
> Smalltalk current createPackage: 'myproject' properties: #{}!
> Widget subclass: #MyProject
>         instanceVariableNames: 'socket'
>         package: 'myproject'!
>
> !MyProject methodsFor: 'not yet classified'!
>
> doit
>     socket emit: 'doPosted' with: 'just  a string'.
> !
>
> establishConnection
>       socket := io connect: '<a href="http://localhost:80'">http://localhost:80'.
>       socket on: 'receivePosted' do: [:data | self showMessage:
> data.].
> !
>
> getit
>     socket emit: 'getPosted' with: ' '.
> !
>
> renderOn: html
>         html div
>                 with: [ html button class: 'btn';
>                             with: 'Connect'; id: 'bc';
>                         onClick: [ self establishConnection]];
>                with: [ html button class: 'btn';
>                             with: 'Emit to socket'; id: 'bdoit';
>                         onClick: [ self doit]];
>                with: [ html button class: 'btn';
>                             with: 'get socket'; id: 'bget';
>                         onClick: [ self getit]].
> !
>
> showMessage: aString
>         | q|
> q := 'body' asJQuery.
> q append: '<p>' , aString, '</p>'.
> ! !
>
> !MyProject class methodsFor: 'not yet classified'!
>
> open
>         self new appendToJQuery: 'body' asJQuery.
> ! !
>
> Regards,
> Jochem
>
> On 21 jun, 22:44, Apostolis Xekoukoulotakis <[hidden email]>
> wrote:
>
>
>
>
>
>
>
> > It would be nice if there was a tutorial for us smalltalkers that dont know
> > javascript how to use the existent javascript libraries.
>
> > On the server side, I didnt have any problems. The reason for that is that
> > I used 'require' to load the socket.io javascript. Then everything worked
> > like a charm.
>
> > On the client side, it seems that loading the javascript outside of the
> > smalltalk class creates problems. And since having a global object would
> > never happen in smalltalk, I dont know how to fix it.
>
> > Jochem, can you pass s on a smalltalk object of a different class without a
> > problem? I noticed that i cannot transfer the socket to the SocketClient.
> > Maybe I am doing something wrong.
>
> > thanks for your help by the way..
Reply | Threaded
Open this post in threaded view
|

Re: nil error - Socket.io JObject

xekoukou
Nice, I made it to work as well. For those that might have the same problems with me, it seems that there is an ongoing discussion how to deal with global variables in this mailing list. Just make a search with: 'global variables' on this list.


2012/6/23 Jochem <[hidden email]>
To make it complete, I have added the Nodejs code, also with a simple
Redis call
What I did to test socket.io is to have one nodejs server running on
port 4000 using the standard server for loading Amber, and another
nodejs server on port 80 to play with socket.io and redis.

start
       http := require value: 'http'.
       redis := require value: 'redis'.

       client := redis createClient.


    (httpServer := http createServer: [:request :response |
       self handleRequest: request respondTo: response]) listen:
'80'.

   io := (require value: 'socket.io') listen: httpServer.
    console log: 'io started'.
    io sockets on: 'connection' do:
       [:socket| socket on: 'doPosted' do:
                    [ :data | client set: 'key' with: data do:
                        [:err :reply |console log: reply]].
                 socket on: 'getPosted' do:
                    [ :data | client get: 'key' do:
                        [:err :reply |socket emit: 'receivePosted'
withData: reply.
                           console log: reply]]].

I am just playing with socket.io and redis, so I do not have a full
application running...

Jochem

On 22 jun, 21:28, Jochem <[hidden email]> wrote:
> Hi Apostolis,
>
> Here is just an example for socket.io on the client :
> Index.html
> <html>
> <head>
> <title>My Project</title>
> <script src="../../js/amber.js" type="text/javascript"></script>
> <script src="../../js/socket/dist/socket.io.js" type="text/
> javascript"></script>
> </head>
> <body>
> <script type="text/javascript">
>         loadAmber({
>                 files: ['myproject.js'],
>                 prefix: 'examples/myproject/js',
>                 ready: function() {  smalltalk.MyProject._open(),
> smalltalk.Browser._open();;
>
>                 }});
> </script>
> </body>
> </html>
>
> Here's the Amber source (.st file)
>
> Smalltalk current createPackage: 'myproject' properties: #{}!
> Widget subclass: #MyProject
>         instanceVariableNames: 'socket'
>         package: 'myproject'!
>
> !MyProject methodsFor: 'not yet classified'!
>
> doit
>     socket emit: 'doPosted' with: 'just  a string'.
> !
>
> establishConnection
>       socket := io connect: 'http://localhost:80'.
>       socket on: 'receivePosted' do: [:data | self showMessage:
> data.].
> !
>
> getit
>     socket emit: 'getPosted' with: ' '.
> !
>
> renderOn: html
>         html div
>                 with: [ html button class: 'btn';
>                             with: 'Connect'; id: 'bc';
>                         onClick: [ self establishConnection]];
>                with: [ html button class: 'btn';
>                             with: 'Emit to socket'; id: 'bdoit';
>                         onClick: [ self doit]];
>                with: [ html button class: 'btn';
>                             with: 'get socket'; id: 'bget';
>                         onClick: [ self getit]].
> !
>
> showMessage: aString
>         | q|
> q := 'body' asJQuery.
> q append: '<p>' , aString, '</p>'.
> ! !
>
> !MyProject class methodsFor: 'not yet classified'!
>
> open
>         self new appendToJQuery: 'body' asJQuery.
> ! !
>
> Regards,
> Jochem
>
> On 21 jun, 22:44, Apostolis Xekoukoulotakis <[hidden email]>
> wrote:
>
>
>
>
>
>
>
> > It would be nice if there was a tutorial for us smalltalkers that dont know
> > javascript how to use the existent javascript libraries.
>
> > On the server side, I didnt have any problems. The reason for that is that
> > I used 'require' to load the socket.io javascript. Then everything worked
> > like a charm.
>
> > On the client side, it seems that loading the javascript outside of the
> > smalltalk class creates problems. And since having a global object would
> > never happen in smalltalk, I dont know how to fix it.
>
> > Jochem, can you pass s on a smalltalk object of a different class without a
> > problem? I noticed that i cannot transfer the socket to the SocketClient.
> > Maybe I am doing something wrong.
>
> > thanks for your help by the way..



--

Sincerely yours, 
     Apostolis Xekoukoulotakis

Reply | Threaded
Open this post in threaded view
|

Re: nil error - Socket.io JObject

Amber Milan Eskridge
Maybe interessting, too:
https://github.com/NicolasPetton/amber/wiki/Getting-started-with-Amber-and-socket.io

On Sat, Jun 23, 2012 at 1:22 PM, Apostolis Xekoukoulotakis <[hidden email]> wrote:
Nice, I made it to work as well. For those that might have the same problems with me, it seems that there is an ongoing discussion how to deal with global variables in this mailing list. Just make a search with: 'global variables' on this list.



2012/6/23 Jochem <[hidden email]>
To make it complete, I have added the Nodejs code, also with a simple
Redis call
What I did to test socket.io is to have one nodejs server running on
port 4000 using the standard server for loading Amber, and another
nodejs server on port 80 to play with socket.io and redis.

start
       http := require value: 'http'.
       redis := require value: 'redis'.

       client := redis createClient.


    (httpServer := http createServer: [:request :response |
       self handleRequest: request respondTo: response]) listen:
'80'.

   io := (require value: 'socket.io') listen: httpServer.
    console log: 'io started'.
    io sockets on: 'connection' do:
       [:socket| socket on: 'doPosted' do:
                    [ :data | client set: 'key' with: data do:
                        [:err :reply |console log: reply]].
                 socket on: 'getPosted' do:
                    [ :data | client get: 'key' do:
                        [:err :reply |socket emit: 'receivePosted'
withData: reply.
                           console log: reply]]].

I am just playing with socket.io and redis, so I do not have a full
application running...

Jochem

On 22 jun, 21:28, Jochem <[hidden email]> wrote:
> Hi Apostolis,
>
> Here is just an example for socket.io on the client :
> Index.html
> <html>
> <head>
> <title>My Project</title>
> <script src="../../js/amber.js" type="text/javascript"></script>
> <script src="../../js/socket/dist/socket.io.js" type="text/
> javascript"></script>
> </head>
> <body>
> <script type="text/javascript">
>         loadAmber({
>                 files: ['myproject.js'],
>                 prefix: 'examples/myproject/js',
>                 ready: function() {  smalltalk.MyProject._open(),
> smalltalk.Browser._open();;
>
>                 }});
> </script>
> </body>
> </html>
>
> Here's the Amber source (.st file)
>
> Smalltalk current createPackage: 'myproject' properties: #{}!
> Widget subclass: #MyProject
>         instanceVariableNames: 'socket'
>         package: 'myproject'!
>
> !MyProject methodsFor: 'not yet classified'!
>
> doit
>     socket emit: 'doPosted' with: 'just  a string'.
> !
>
> establishConnection
>       socket := io connect: 'http://localhost:80'.
>       socket on: 'receivePosted' do: [:data | self showMessage:
> data.].
> !
>
> getit
>     socket emit: 'getPosted' with: ' '.
> !
>
> renderOn: html
>         html div
>                 with: [ html button class: 'btn';
>                             with: 'Connect'; id: 'bc';
>                         onClick: [ self establishConnection]];
>                with: [ html button class: 'btn';
>                             with: 'Emit to socket'; id: 'bdoit';
>                         onClick: [ self doit]];
>                with: [ html button class: 'btn';
>                             with: 'get socket'; id: 'bget';
>                         onClick: [ self getit]].
> !
>
> showMessage: aString
>         | q|
> q := 'body' asJQuery.
> q append: '<p>' , aString, '</p>'.
> ! !
>
> !MyProject class methodsFor: 'not yet classified'!
>
> open
>         self new appendToJQuery: 'body' asJQuery.
> ! !
>
> Regards,
> Jochem
>
> On 21 jun, 22:44, Apostolis Xekoukoulotakis <[hidden email]>
> wrote:
>
>
>
>
>
>
>
> > It would be nice if there was a tutorial for us smalltalkers that dont know
> > javascript how to use the existent javascript libraries.
>
> > On the server side, I didnt have any problems. The reason for that is that
> > I used 'require' to load the socket.io javascript. Then everything worked
> > like a charm.
>
> > On the client side, it seems that loading the javascript outside of the
> > smalltalk class creates problems. And since having a global object would
> > never happen in smalltalk, I dont know how to fix it.
>
> > Jochem, can you pass s on a smalltalk object of a different class without a
> > problem? I noticed that i cannot transfer the socket to the SocketClient.
> > Maybe I am doing something wrong.
>
> > thanks for your help by the way..



--

Sincerely yours, 
     Apostolis Xekoukoulotakis