Bonjour,
dans mon apprentissage de Flex et d'AS3, je cherche aujourd'hui à créer un serveur de socket couplé à Flex. Le serveur est réalisé via PHP et est fonctionnel (testé en full PHP). Maintenant, j'ai crée un petit projet Flex pour tester mon serveur mais j'obtiens l'erreur suivante (je bosse en local via wamp server) :
Voici mon arborescence (la plus simple possible en fait...) :securityErrorHandler: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048"]
http://localhost/flex_socket/test.html -> mon projet Flex
http://localhost/socket/Serveur.php -> mon serveur de socket
J'ai testé de créer un fichier crossdomain.xml sous http://localhost/ et http://localhost/socket/ mais j'ai le même résultat. Voici le crossdomain :
J'ai testé plusieurs versions de crossdomain pour le même résultat...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM " http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <site-control permitted-cross-domain-policies="all" /> <allow-access-from domain="127.0.0.1" to-ports="*" secure="false"/> <allow-http-request-headers-from domain="127.0.0.1"/> </cross-domain-policy>
Voici les sources Flex de mon projet :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" xmlns:mx1="library://ns.adobe.com/flex/mx" creationComplete="init()"> <s:layout> <s:VerticalLayout /> </s:layout> <fx:Script> <![CDATA[ import sockets.SocketPerso; private var _socket:SocketPerso; private function init():void { _socket = new SocketPerso(); _socket.connect("127.0.0.1", 25854); } ]]> </fx:Script> </s:Application>
Une idée ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 package sockets { import flash.events.Event; import flash.events.IOErrorEvent; import flash.events.ProgressEvent; import flash.events.SecurityErrorEvent; import flash.net.Socket; import mx.controls.Alert; public class SocketPerso extends Socket { public function SocketPerso(host:String=null, port:int=0) { super(); configureListeners(); if(host && port) super.connect(host, port); } private function configureListeners():void { addEventListener(Event.CLOSE, closeHandler); addEventListener(Event.CONNECT, connectHandler); addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler); } private function closeHandler(event:Event):void { Alert.show("closeHandler: " + String(event)); } private function connectHandler(event:Event):void { Alert.show("connectHandler: " + String(event)); sendRequest(); } private function sendRequest():void { writeUTFBytes("test"); flush(); } private function ioErrorHandler(event:IOErrorEvent):void { Alert.show("ioErrorHandler: " + String(event)); } private function securityErrorHandler(event:SecurityErrorEvent):void { Alert.show("securityErrorHandler: " + String(event)); } private function socketDataHandler(event:ProgressEvent):void { Alert.show("socketDataHandler: " + String(event)); readResponse(); } private function readResponse():void { Alert.show(readUTFBytes(bytesAvailable)); } } }
Merci
Partager