|
|
|||||
Регистрация: Oct 2006
Адрес: https://twitter.com/Eric_Gurt
Сообщений: 393
|
Socket securityError :: Error #2048
Всем добрый вечер
Когда я запускаю флэшку в IDE, все работает замечательно, но при запуске из браузера Socket выдает ошибку... Для создания подключения в коде флэшки as3: var MP_SERVER_IP:String="91.200.106.130"; var MP_SERVER_PORT:int=10014; var MP_socket:Socket = new Socket(); Security.loadPolicyFile("http://"+MP_SERVER_IP+"/crossdomain.xml"); MP_socket.connect(MP_SERVER_IP, MP_SERVER_PORT); -= Server =- New client connected: 91.200.106.130 (Total 1 clients) -- Client said: <policy-file-request/>� client requested crossdomain.xml sending... -- Client said: client disconnected. [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048"] <? header('Content-Type: text/plain;'); error_reporting(E_ALL ^ E_WARNING); set_time_limit(0); ob_implicit_flush(); ob_end_flush(); echo "-= Server =-\n\n"; include("adm.php"); $address = '0.0.0.0'; $port = 10014; $max_clients = 128; $crossdomain = '<cross-domain-policy><allow-access-from domain="*" secure="false" to-ports="'.$port.'"/></cross-domain-policy>'; $trrr=0; // create a streaming socket, of type TCP/IP $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); // set the option to reuse the port socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1); // "bind" the socket to the address to "localhost", on port $port // so this means that all connections on this port are now our resposibility to send/recv data, disconnect, etc.. // socket_bind($sock, 0, $port); socket_bind($sock, $address, $port) or die('Could not bind to address'); // start listen for connections socket_listen($sock); // create a list of all the clients that will be connected to us.. // add the listening socket to this list $clients = array($sock); while (true) { @ob_flush(); // create a copy, so $clients doesn't get modified by socket_select() $read = $clients; // get a list of all the clients that have data to be read from // if there are no clients with data, go to next iteration if (socket_select($read, $write = NULL, $except = NULL, 0) < 1) continue; // check if there is a client trying to connect if (in_array($sock, $read)) { // accept the client, and add him to the $clients array $clients[] = $newsock = socket_accept($sock); // send the client a welcome message //socket_write($newsock, "no noobs, but ill make an exception :)\n"."There are ".(count($clients) - 1)." client(s) connected to the server\n"); socket_write($newsock, $crossdomain, strlen($crossdomain)); socket_write($newsock, $crossdomain, strlen($crossdomain)); socket_getpeername($newsock, $ip); echo "New client connected: {$ip} (Total ".(count($clients) - 1)." clients)\n"; // remove the listening socket from the clients-with-data array $key = array_search($sock, $read); unset($read[$key]); } // loop through all the clients that have data to read from foreach ($read as $read_sock) { if (false === ($data = socket_read($read_sock, 1024))) { echo 'socket_read() failed: '.socket_strerror(socket_last_error())."\n"; } echo ' -- Client said: '.$data."\n"; // check if the client is disconnected //echo ; if (strlen($data)==0 && ord($data)==0) //if ($data=='') { // remove client for $clients array $key = array_search($read_sock, $clients); unset($clients[$key]); echo "client disconnected.\n"; // continue to the next client to read from, if any continue; } // trim off the trailing/beginning white spaces $data = trim($data); //if ($data == '<policy-file-request/>') if (substr($data, 0, 12) == substr('<policy-file-request/>', 0, 12)) { echo "client requested crossdomain.xml sending...\n"; socket_write($send_sock, $crossdomain, strlen($crossdomain)); } else { $ans='Beep'; echo 'Sending "'.$ans.'"'."\n"; socket_write($send_sock, $ans, strlen($ans)); //$data=$ans; //$trrr++; } // check if there is any data after trimming off the spaces if (!empty($data)) { // send this to all the clients in the $clients array (except the first one, which is a listening socket) foreach ($clients as $send_sock) { // if its the listening sock or the client that we got the message from, go to the next one in the list if ($send_sock == $sock || $send_sock == $read_sock) // continue; // write the message to the client -- add a newline character to the end of the message socket_write($send_sock, $data."\n"); } // end of broadcast foreach } } // end of reading foreach } // close the listening socket socket_close($sock); ?>
__________________
x << 2; |
|
|||||
кроссдомейн оно просит по 443 порту, а если там нет, то у сокета. вроде так.
и еще у XMLSocket строки нуль-треминированные, не работает у вас поэтому, наверное. Добавлено через 3 минуты сорри, у вас Socket, а не XMLSocket. попоробуйте флюшить его после записи в него кроссдомейна. |
|
|||||
Внимательно читаем и ищем отличия:
Цитата:
Цитата:
Цитата:
__________________
...вселенская грусть |
|
|||||
Регистрация: Oct 2006
Адрес: https://twitter.com/Eric_Gurt
Сообщений: 393
|
мм а как именно это можно сделать?
Попробовал вставить после выдало ошибку, попробовал после и тоже выдало ошибку, и среди PHP функций для работы с socket'ами flush ф-ций тоже не нашел 2gloomyBrain вроде бы файл запрашивается правильно (или нет?), но flash на него никак не реагирует
__________________
x << 2; |
|
|||||
Регистрация: Oct 2006
Адрес: https://twitter.com/Eric_Gurt
Сообщений: 393
|
Цитата:
Цитата:
на теперь флэшка нулевой байт не шлет и не отключается до закрытия всей страницы с флэшкой. в логе
__________________
x << 2; |
|
|||||
вы путаете понятия нулевой байт с...даже не знаю как это назвать.
Вобщем, нулевой байт - это байт с кодом ноль �. У вас в логе он расположен самым последним символом, сразу после "<policy-file-request/>" в той же строке. А вторая надпись в логе " -- Client said:" -- это никакой не нулевой байт, это вообще не байт, там пустой буфер. Если вы там сделаете echo strlen($data), то получите 0. А если вы еще и распечатете там часики, то увидите, что клиент дропает сокет не сразу, а по истечении таймаута. это наводит на мысль, что можно попытаться отдавать полиси нуль-терминированным. Попробуйте. то есть после присвоения прицепляете в конец ноль: $crossdomain .= "\0"; и потом уже с ним работаете. c XMLSocket только так и работает. кстати, у вас кроссдомейн странный. нате вам мой, с уже прцепленным нулем:
когда заработает будете последовательными приближениям приближать к своему варианту и так найдете где он там спотыкается. Последний раз редактировалось chabapok; 16.10.2010 в 18:44. |
|
|||||
Регистрация: Oct 2006
Адрес: https://twitter.com/Eric_Gurt
Сообщений: 393
|
При запуске флэшки из браузера с debug версией флэша, спустя 15 секунд после подключения:
Connection securityError: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048: Нарушение изолированной среды: http://91.200.106.130/xxx.swf?36072 не может загрузить данные из 91.200.106.130:10014."] В логе все происходит в одну секунду, после "<policy-file-request/>" флэшка сразу шлет пустой буффер: [07:16:43] New client connected: 91.200.106.130 (Total 1 clients) [07:16:43] -- Client said: <policy-file-request/>� [07:16:43] client requested crossdomain.xml sending... [07:16:43] -- Client said: [07:16:43] client disconnected. Код сервера: ... $address = '0.0.0.0'; $port = 10014; $crossdomain="<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"$port\" /></cross-domain-policy>\0"; ... if (strlen($data)==0 && ord($data)==0) // так было в одном из примеров, с которого все началось // сервер отключается при получении пустого буфера { // remove client for $clients array $key = array_search($read_sock, $clients); unset($clients[$key]); echo date("[H:i:s] ")."client disconnected.\n"; // continue to the next client to read from, if any continue; } if (substr($data, 0, 12) == substr('<policy-file-request/>', 0, 12)) // отправка policy { echo date("[H:i:s] ")."client requested crossdomain.xml sending...\n"; socket_write($send_sock, $crossdomain, strlen($crossdomain)); } ... PS: пробовал убрать из php скрипта отключение при получении пустого буфера (почему он приходит?), и тогда флэшка шлет их тысячами после запроса полиции. Может это что-то значит?
__________________
x << 2; Последний раз редактировалось Eric Gurt; 16.10.2010 в 19:54. |
|
|||||
Цитата:
Цитата:
После отключения флешка должна подключиться заново. Если этого не происходит - значит Вы отдаете некорректный policy файл.
__________________
...вселенская грусть |
Часовой пояс GMT +4, время: 23:17. |
|
« Предыдущая тема | Следующая тема » |
|
|