2
votes

I'm having a problem to receive data from socket.io to Flash (actionscript).

I've tried:

Server (nodejs) socket.io :

var io = require('socket.io').listen(9000);
setInterval(function() {
io.sockets.emit('hello');
console.log("test");
}, 500 );

Client (actionscript) Socket();

import flash.net.Socket;
import flash.events.*;
var socket:Socket = new Socket();
Security.allowDomain("*");
socket.connect("localhost", 9000);
socket.addEventListener(Event.CONNECT, onConnect);
socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
function onConnect( evt:Event ):void
{
trace( "Connected to flash");
}
function socketDataHandler(evt:ProgressEvent):void  
{  
trace("socketDataHandler: " + evt);
}  

Output

Flash connects succesful to the server and trace "Connected to flash" but it cannot receive data. Any ideas?

2
Maybe this can help you wellconsidered.be/post/10519721421/… An article writing by Pieter Michels. - user1796321
Please have a look this tutorial which help me: <a>rivellomultimediaconsulting.com/…> - user3346085

2 Answers

0
votes

See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html#includeExamplesSummary and look at the method called readResponse.

You need to read the bytes from the stream.

Or just use that very example and you'll know that there is not something wrong with the client-side functionality.

0
votes

Well I don't think that will work, because socket.io has it's own protocol which uses several transport methods such as websocket. But your action script is just having a normal flash socket I believe. The best is that you use the normal socket.io javascript client and and use a messaging system to communicate with your action script client. In this case, I think this link is useful for you, in which describes this messaging.

Update:

These libraries may be what you are looking for: https://github.com/ascorbic/socket-io-actionscript https://github.com/simb/FlashSocket.IO