-
.
socket
Hi,
Has anybody had any success in using AS3 socket, I have various ways of connecting and sometimes it does but closes automatically after a few seconds, I also get invalid socket after closing when trying to send message.
I have tried with numerous ports and various combinations of the local, site, external etc ect.
I never get the connected message whilst online
PHP Code:
import flash.net.Socket; import flash.events.*;
var socket:Socket = new Socket(); var port:Number= 80;
var site:String = "fruitbeard.net"; var local:String = "127.0.0.1"; var external:String = "176.24.181.163";
Security.allowDomain("*"); Security.allowInsecureDomain("*"); Security.loadPolicyFile("http://" + site + "/crossdomain.xml"); //Security.loadPolicyFile("xmlsocket://" + local + ":" + String(port));
socket.addEventListener(Event.CONNECT, onConnect); socket.addEventListener(Event.CLOSE, onClose); socket.addEventListener(IOErrorEvent.IO_ERROR, onError); socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse); socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError);
//socket.connect(site, port); //socket.connect(local, port); //socket.connect(external, port); socket.connect(site, port);
function onConnect(e:Event):void { //socket.writeUTFBytes("GET / HTTP/1.1\n"); //socket.writeUTFBytes("Host: fruitbeard.net\n"); //socket.writeUTFBytes("\n"); socket.flush(); chatArea.htmlText += "<u>Connected</u>\n<font color='#0066ff'>" + e; }
function onClose(e:Event):void { socket.flush(); socket.close(); chatArea.htmlText += "<u><font color='#ff5500'>Disconnected</font></u>\n<font color='#0066ff'>" + e; }
function onError(e:IOErrorEvent):void { trace("IO Error: " + e); chatArea.htmlText += "<u><font color='#ff5500'>IO Error</font></u>\n<font color='#0066ff'>" + e; }
function onSecError(e:SecurityErrorEvent):void { trace("Security Error: " + e); chatArea.htmlText += "<u><font color='#ff5500'>Security Error</font></u>\n<font color='#0066ff'>" + e; }
function onResponse(e:ProgressEvent):void { if (socket.bytesAvailable > 0) { var readMessage:String = String(socket.readUTFBytes(socket.bytesAvailable)); //trace(readMessage); chatArea.htmlText += readMessage; socket.flush(); readMessage = ""; } }
sendButt.addEventListener(MouseEvent.CLICK, sendBytes); sendButt.buttonMode = true;
function sendBytes(e:MouseEvent) { if (pMessage.text != "") { var sendMessage:String = pMessage.text + "\r\n"; //trace(sendMessage); socket.writeUTFBytes(sendMessage); sendMessage = ""; pMessage.text = ""; } }
and my crossdomain which is on the server is simply
Code:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" to-ports="*" />
</cross-domain-policy>
any solutions most welcomed
I beleive its probably the crossdomain / policy file, but I'm stuck as the errors whilst online are always 2048 security
-
Designer, Programmer, Musician
I was playing with Socket and ServerSocket last year and achieve some cool things. But I prefer Yahoo's PlayerIO. Have you tested playerio already?
Regards
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
Hi,
My problem is my web host does not allow port binding with the current plan I have.
I don't really actually need it and it was just for experiment, I do use smartfox on occasion.
Thanks for the inputus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|