日期:2014-05-18  浏览次数:20973 次

c# socket 与 Flash XMLSocket 策略文件传输 问题,高手来~~!!
现在基本上了解了 Flash XMLSocket 的基本应用,问题在于传输的安全策略问题,一直弄不明白,望高人指点,给点源码更是感激不尽,在线等,分不够再加~!
Flash 基本源码:
socket = new XMLSocket();
socket.onConnect = function(success) {
  if (success) {
trace("Connection succeeded!");
  } else {
trace("Connection failed!");
  }
};
socket.onClose = function(){
//
}
if (!socket.connect(null, 6500)) {
  trace("connectionFailed");
} else {
  trace("waitForConnection");
}
socket.onData = function(doc) {
  trace("asddddddddddd=="+doc.length);
  trace(doc);
};


------解决方案--------------------
C/C++ code

MFC定义 
 CString privacyXml;
   privacyXml = "<cross-domain-policy>\
    <allow-access-from domain=\"*\" to-ports=\"5678\" />\ 
    </cross-domain-policy>";
    if(strcmp(clientobj->RecvDataBuf.buf,"<policy-file-request/>") == 0) //请求策略文件
                {
                    strcpy(clientobj->RecvDataBuf.buf,privacyXml);
                    SendBytes = sizeof(privacyXml);
                    g_pchatserver->m_Client->optype = OP_IOWrite;
                    if (WSASend(g_pchatserver->m_Client->sclient, &(g_pchatserver->m_Client->RecvDataBuf), 1, &SendBytes, 0,
                        &(g_pchatserver->m_Client->ol), NULL) == SOCKET_ERROR)
                    {
                        if (WSAGetLastError() != ERROR_IO_PENDING)
                        {
                            wsprintf(errormsg,"WSASend() failed with error %d", WSAGetLastError());
                            ::MessageBox(NULL,errormsg,"Error",MB_OK);
                            return -1;
                        }
                    }
                    break;
                }

------解决方案--------------------
因为flash在和服务器通信的时候会首先连接843端口,如果连接不上flash就会寻找服务器其它在监听的端口进行连接并且发送<policy-file-request/> \0,这个时候你需要发送策略文件给flash,至于策略文件是什么,"<cross-domain-policy> "+"<allow-access-from domain=\"*\" to-ports=\"1025-9999\"/>"+"</cross-domain-policy> "+(char)0 这个字串就是策略文件的内容,你把这个字串发送给flash就可以了