socket.io 1.0 with titanium (appcelerator)

Created on 4 Jun 2014  ·  42Comments  ·  Source: socketio/socket.io

exist a version of socket.io 1.0 to use with titanium (appcelerator) ?

or can we use 0.96 client with 1.0 server ?

cordially

All 42 comments

socket.io its a module for NodeJS.
If you need add SOCKET.IO into your proyect only put:

<script src="https://cdn.socket.io/socket.io-1.x.x.js"></script>
<!--source: http://socket.io/blog/socket-io-1-0-4/-->

and make sure you have your server running socket.io

Thank you, but this file when we use a Webview. What I need a file adopted for titanium like this one

https://gist.github.com/iamyellow/3071689

Cordially

What I need is for native use as library, not in Webview

You need to create a native module with socketrocket (or use net.iamyellow.tiws) and slighty adjust the socket.io client so it uses that, does not use window, uses Ti.Network.createHTTPClient() and stub xdomainCheck. I might update my fork (https://github.com/HilkoLantinga/tiws) next week.

Do you really need socket.io? You could use ws in node and net.iamyellow.tiws in Appcelerator Titanium if all your clients support websockets. Or also pipe to a tcp socket for your Titanium clients if you don't use TLS (as far as I know Titanium does not support TLS with TCP, so you would need another native module for that).

That being said... Maybe I could make my adjustments in such a way that they can be integrated in engine.io-client (and maybe when needed socket.io-client), so it runs in node, a browser and Appcelerator Titanium + net.iamyellow.tiws. Is a Pull Request for something like that acceptable for Automattic?

+1

We're working on out-of-the-box Titanium support. Will keep you guys posted

any news about titanium support for the new version 1.0?

I'm still trying, no luck so far. But got some work I need to finish first, will have a 3th look after this weekend.

Any updates on this?

Can't get it to connect no matter what I do, tried websockets and long poll. I really don't get it, 0.8.x and 0.9.x where so easy.

:+1: I also tried while 1.0 was in beta.
It seems to be very hard because socket.io reference a lot of external libraries like engine.io etc.

I'm using tiws and version 0.9.11 both on client and server. It works like a charm on android, but the iphone version crashes after connection. Here the article in Q&A.

Use my 0.9.16 version, that works perfectly on iOS (5, 6 and 7).

Do you mean this: https://github.com/HilkoLantinga/socket.io-client/blob/master/socket.io.js ? It seams to be a pure JS version

You use that with tiws.

OK, I found. thanx.

n.intersect = function(e, t) {
            var r = [], i = e.length > t.length ? e : t, s = e.length > t.length ? t : e;
            for (var o = 0, u = s.length; o < u; o++) {
                if (~n.indexOf(i, s[o])) {  // <== is it correct, I'm wondering
                    r.push(s[o])
                }
            }
            return r
        };

OK, I can my compile app with your js file without issues. But on runtime it crashes the app.
What version of socket.io do you use on server?

0.9.16, I do something like this on the client:

var io = require('socket.io'),
    socket = io.connect('http://10.10.10.10:8188', {
        'transports' : ['websocket'],
        'reconnect' : true,
        'reconnection delay' : 100,
        'reconnection limit' : 5000,
        'max reconnection attempts' : Infinity,
        'query' : 'description=' + Ti.Network.encodeURIComponent(Ti.App.description) + '&guid=' + Ti.App.guid + '&id=' + Ti.App.id + '&name=' + Ti.App.name + '&version=' + Ti.App.version + '&installId=' + Ti.App.installId
    });

Server is something like this:

var app = require('express')(),
    server = require('http').Server(app),
    io = require('socket.io')(server);
server.listen(8188);

Hi Hilko,

Thanks, I will try to embed your code or use it for inspiration. Now I
start in this manner:

var Cligga = function() {
this.eventhandlers = [];
this.socket =
require('vendor/socket.io.0.9.16').connect('ws://134.100.29.95:1334', {
transports : ['websocket'],
'reconnect' : true,
'reconnection delay' : 100,
'reconnection limit' : 5000,
'max reconnection attempts' : Infinity,
});
console.log('Info: socket connected ~~~' + this.socket);
this.socket.on('connect', function() {
Ti.API.log('connected!');
});

After connecting, this in on console:

[DEBUG] : Loading:
/var/mobile/Applications/E6A8050E-494A-4FB1-9688-C510FEAD936B/Cligga.app/controls/cligga.adapter.js,
Resource: controls/cligga_adapter_js
[INFO] : Info: socket connected ~~~[object Object]
[DEBUG] : Loading:
/var/mobile/Applications/E6A8050E-494A-4FB1-9688-C510FEAD936B/Cligga.app/vendor/socket.io.0.9.16.js,
Resource: vendor/socket_io_0_9_16_js

I'm wondering:

first the connected status (from my output) and the the module loading …

Cheers!

Rainer

On 13/07/14 13:54, Hilko Lantinga wrote:

'reconnect' : true,
'reconnection delay' : 100,
'reconnection limit' : 5000,
'max reconnection attempts' : Infinity,

_Dipl.-Ing. Rainer Schleevoigt_
Certified TYPO3 Integrator
Certified Titanium App Developer

Novalisweg 10

22303 Hamburg
℡ 040 27806982
|Ust-ID: DE239491976|||||||

So it works for you now? If so, great and enjoy, if not I don't see any error in your output.

On 13/07/14 14:14, Hilko Lantinga wrote:

So it works for you now? If so, great and enjoy, if not I don't see
any error in your output.

This is the problem, it crashes and I dont see any messages.

On server I have different logs depending on Android/iOS. At iOS I miss
a line.

Here the outout of android request on server:

debug: client authorized
info: handshake authorized crqMwdAhZnSJ_AVsPKBd
debug: setting request GET/socket.io/1/websocket/crqMwdAhZnSJ_AVsPKBd
debug: client authorizedfor
debug: websocket writing1::

and the same if iOS connect:

debug: client authorized
info: handshake authorized lTC9by6zi_2KS25SPKBc
debug: websocket writing2::

As you can see: on iOS the line

setting request GET/socket.io/1/websocket/crqMwdAhZnSJ_AVsPKBd

is missing.


Reply to this email directly or view it on GitHub
https://github.com/Automattic/socket.io/issues/1590#issuecomment-48838941.

_Dipl.-Ing. Rainer Schleevoigt_
Certified TYPO3 Integrator
Certified Titanium App Developer

Novalisweg 10

22303 Hamburg
℡ 040 27806982
|Ust-ID: DE239491976|||||||

the problem is with the new version 1.0
it works fine with 0.9 ...
but today socket 1.0 is more efficient, so we need a 1.0 client

i hope that you will get a solution quickly

On 13/07/14 14:37, fadaytak wrote:

the problem is with the new version 1.0
it works fine with 0.9 ...

I have unstall with

npm install socket.[email protected]

I think too that 1.0 is better…

but today socket 1.0 is more efficient, so we need a 1.0 client

i hope that you will get a solution quickly

In last two weeks I'm working with the issue, but I see any solution.


Reply to this email directly or view it on GitHub
https://github.com/Automattic/socket.io/issues/1590#issuecomment-48839422.

_Dipl.-Ing. Rainer Schleevoigt_
Certified TYPO3 Integrator
Certified Titanium App Developer

Novalisweg 10

22303 Hamburg
℡ 040 27806982
|Ust-ID: DE239491976|||||||

For titanium it doesn't matter. But if you have browser clients too then 1.0 makes sense.

I'm not counting on a quick solution from my side. I've started at a new job this week that requires a lot of flying, so I will not have the time. Maybe if I'm really lucky and find a quick fix.

Rainer, could you create a small app that does not work and make a repo for it?

On 13/07/14 14:45, Hilko Lantinga wrote:

For titanium it does matter. But if you have browser clients too then
1.0 makes sense.

my plan was to work with native views. Now I think about a push not
solution.
My goal is a voting app for education procresses.


Reply to this email directly or view it on GitHub
https://github.com/Automattic/socket.io/issues/1590#issuecomment-48839570.

_Dipl.-Ing. Rainer Schleevoigt_
Certified TYPO3 Integrator
Certified Titanium App Developer

Novalisweg 10

22303 Hamburg
℡ 040 27806982
|Ust-ID: DE239491976|||||||

Any update?

Hey Guys any news on SocketIo 1.0 on titanium? Thank you so much for working on it!

I've given up, using 0.9.16 for now.

Op 6 okt. 2014 om 19:22 heeft nicco [email protected] het volgende geschreven:

Hey Guys any news on SocketIo 1.0 on titanium? Thank you so much for working on it!


Reply to this email directly or view it on GitHub.

this looks promising, the also use browserify

https://github.com/smclab/titaniumifier

but as of now:

With titaniumifier, you will not be able to use or depend on ‘complex’ e ‘deeply’ node-ish packages like socket.io;

…but…

we worked (and still working) on providing a solution to use every Node.js package directly in your app

I'm using socket.io version 0.9.16 and works fine on simulator but when I try to connect on iPhone 5C iOS 8.1 nothing happens =(

Someone can help? Thanks

I was trying to run on localhost on my iphone... that's why nothing happens I guess hahaha
Any news about latest version of socket.io?
Thanks for your code @HilkoLantinga

Please watch the discussion at omorandi/tiws#9 to get updates.

I’m the maintainer of titaniumifier at @smclab, and we’re working on a titaniumified solution for socket.io.

Any news about this threat?
I reaaaally need socket.io 1.0 on titanium =/

@yuchi did you make any progress on this? Do you have some code that is partially working and/or that you can share and maybe others can help/contribute?

Any Success ?? Is there Socket.io client for Titanium now ? My Server is on Socket.io 1.4.5.

Maybe (idea) we looking to Titanium pubnub implemenation. This is done with pure TiJS:
https://github.com/pubnub/javascript/blob/master/titanium/lib/platform.js

I'm working on this and wrote a module. It's working so far. Stay tuned.

Thanks

@AppWerft By now it supports only iOS and installation process is so complicated. And many functions are left undone, but works.

https://github.com/yagitoshiro/TiSocketIOClient

var socket, io;

io = require('ro.toshi.ti.mod.tisocketio');
socket = io.createSocket({
  url: 'http://localhost:9999/'
});

socket.on('connect', function(){
  Ti.API.info('connected');
  socket.emit('fromClient', {message: 'Hello'});
});

socket.on('message', function(e){
  Ti.API.info(e);
});

socket.connect();

$.index.addEventListener('close', function(){
  socket.disconnect();
});

Any news?

Just in case someone stumbles upon this, there is an official module by now: https://github.com/appcelerator-modules/titanium-socketio

Was this page helpful?
0 / 5 - 0 ratings