亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

ActionScript 3.0中用XMLSocket與服務(wù)器通訊程序(源碼)

 更新時(shí)間:2009年02月16日 12:44:28   作者:  
一個(gè)簡(jiǎn)單的基于XMLSocket的封裝類
復(fù)制代碼 代碼如下:

//
// CXMLSocket.as
//
//
// Written by Leezhm, 20th Oct, 2008
// Contact : Leezhm@luxoom.cn
//
package
{
import flash.events.DataEvent;
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.net.XMLSocket;
import flash.system.Security;
public class CXMLSocket extends XMLSocket
{
// declare variables
private var mHostName:String = "127.0.0.1";
private var mPort:int = 7654;
private var mStrRecvBuf:String;
// constructor
public function CXMLSocket():void
{
//ConfigNetEvent(this);
Connect();
}
public function Connect():void
{
var xmlStr:String = "xmlsocket://";
xmlStr += mHostName;
xmlStr += ":";
xmlStr += mPort;
Security.loadPolicyFile(xmlStr);
trace(xmlStr);
ConfigNetEvent(this);
this.connect(mHostName, mPort);
}
private function ConfigNetEvent(dispatcher:IEventDispatcher):void
{
dispatcher.addEventListener(Event.CONNECT, OnConnect);
dispatcher.addEventListener(Event.CLOSE, OnClose);
dispatcher.addEventListener(DataEvent.DATA, OnSocketData);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, OnIOError);
dispatcher.addEventListener(ProgressEvent.PROGRESS, OnProgress);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, OnSecurityError);
}
private function OnConnect(ArgEvent:Event):void
{
trace("OnConnect--->" + ArgEvent);
this.send("Connected");
}
private function OnClose(ArgEvent:Event):void
{
trace("OnClose--->" + ArgEvent);
}
private function OnSocketData(ArgEvent:DataEvent):void
{
trace(ArgEvent.text);
}
private function OnIOError(ArgEvent:IOErrorEvent):void
{
trace("OnIOError--->" + ArgEvent.text);
}
private function OnProgress(ArgEvent:ProgressEvent):void
{
trace("OnProgress--->" + ArgEvent.bytesLoaded +
" Total:" + ArgEvent.bytesTotal);
}
private function OnSecurityError(ArgEvent:SecurityErrorEvent):void
{
trace("OnSecurityError--->" + ArgEvent);
}
}
}

基于C++的服務(wù)器源碼:
復(fù)制代碼 代碼如下:

// Server.cpp : implementation file
//
#include "stdafx.h"
#include "Server.h"
#include "SerialPort.h"
extern CSerialPort m_Ports;
// CServer
extern CPtrArray gSocketArr;
extern bool gbIsConnected;
CServer::CServer():mStrSendBuf("")
{
//bIsConnectFlash = false;
}
CServer::~CServer()
{
}
// CServer member functions
void CServer::OnAccept(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
if(0 == nErrorCode)
{
CServer * pSocket = new CServer();
if(SOCKET_ERROR != this->Accept(*pSocket))
{
gSocketArr.Add(pSocket);
}
else
{
::AfxMessageBox(_T("Accept->Error"));
}
pSocket = NULL;
}
CAsyncSocket::OnAccept(nErrorCode);
}
void CServer::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
if(0 == nErrorCode)
{
char buf[30] = {0};
int nRead = this->Receive(buf, 30);
if(0 != nRead && SOCKET_ERROR != nRead)
{
//
// debug info
//
std::fstream debug;
debug.open(_T("Debug.txt"), std::ios::app);
int yvalue;
if(debug.is_open())
{
debug<<buf<<"\n";
yvalue = atoi(buf);
//m_Ports.WriteToPort(
}
debug.close();
if(0 == strcmp("<policy-file-request/>", buf))
{
std::string strXML = "<cross-domain-policy>";
strXML += "<allow-access-from domain=\"*\"to-ports=\"*\"/>";
//strXML += "<allow-access-from domain=\"localhost\"to-ports=\"1025,9999\"/>";
strXML += "</cross-domain-policy>";
strXML += "\0\0";
this->Send(strXML.c_str(), (int)strXML.length() + 1);
gbIsConnected = true;
}
else if(0 == strcmp("Connected", buf))
{
////::AfxMessageBox(_T("Hello"));
gbIsConnected = true;
}
}
}
CAsyncSocket::OnReceive(nErrorCode);
}
void CServer::SendData()
{
if(0 == gSocketArr.IsEmpty())
{
for(int i = 0; i < gSocketArr.GetSize(); i++)
{
((CServer *)gSocketArr[i])->Send(mStrSendBuf.c_str(), (int)mStrSendBuf.length() + 1);
}
std::fstream debug;
debug.open(_T("Debug.txt"), std::ios::app);
int yvalue;
if(debug.is_open())
{
debug<<mStrSendBuf<<"\n";
}
debug.close();
}
else
{
::AfxMessageBox(_T("Socket Error"));
}
}
注意服務(wù)器端程序是繼承了MFC中CAsyncSocket的一個(gè)異步socket類

相關(guān)文章

  • Actionscript 3.0 鼠標(biāo)事件

    Actionscript 3.0 鼠標(biāo)事件

    這本書(shū)是一本經(jīng)典的書(shū)籍,說(shuō)實(shí)話一些小的AS3的項(xiàng)目是做了好幾個(gè),基本的語(yǔ)法也都知道(其實(shí)有面向?qū)ο缶幊陶Z(yǔ)言的基礎(chǔ)后再入門一門新的語(yǔ)言還是很快的)。現(xiàn)在找到了這邊經(jīng)典書(shū)籍完整版,就好好看看,順便寫(xiě)一些總結(jié)。
    2009-02-02
  • AS3 navigateToURL導(dǎo)致ExternalInterface 執(zhí)行失敗問(wèn)題

    AS3 navigateToURL導(dǎo)致ExternalInterface 執(zhí)行失敗問(wèn)題

    AS3 navigateToURL導(dǎo)致ExternalInterface 執(zhí)行失敗問(wèn)題
    2009-02-02
  • AS3打開(kāi)新窗口不被屏蔽的代碼

    AS3打開(kāi)新窗口不被屏蔽的代碼

    有時(shí)候flash打開(kāi)的網(wǎng)址會(huì)出現(xiàn)被屏蔽的現(xiàn)象,如何能輕松的打開(kāi)而不被屏蔽呢,下面是具體的代碼。
    2010-08-08
  • AS3自寫(xiě)類整理筆記:ByteLoader類

    AS3自寫(xiě)類整理筆記:ByteLoader類

    該類的主要功能是把swf,jpg,png,gif等文件以字節(jié)的形式加載進(jìn)來(lái) 以便于使用Loader.loadBytes方法,重復(fù)加載使用素材 如果圖片格式為jpg,并且是漸進(jìn)式格式j(luò)peg,那么該類還可以幫助你邊加載邊顯示
    2008-06-06
  • AS3 中的package(包)應(yīng)用實(shí)例代碼

    AS3 中的package(包)應(yīng)用實(shí)例代碼

    初學(xué)者在學(xué)習(xí)AS3時(shí)會(huì)遇到什么樣的問(wèn)題呢?只有從初學(xué)的角度來(lái)實(shí)踐,才能知道,package 這個(gè)高手們必玩的內(nèi)容,對(duì)初學(xué)者來(lái)說(shuō)或許就有一些困惑。
    2008-08-08
  • as3 rollOver or mouseOver使用說(shuō)明

    as3 rollOver or mouseOver使用說(shuō)明

    rollOver與mouseOver同樣在鼠標(biāo)移到目標(biāo)上時(shí)觸發(fā)事件,細(xì)微區(qū)別在于,mouseOver的bubbles等于true,而rollOver的bubbles是false.
    2009-10-10
  • As3.0 xml + Loader應(yīng)用代碼

    As3.0 xml + Loader應(yīng)用代碼

    簡(jiǎn)單說(shuō)說(shuō)AS3.0中對(duì)于XML支持的不同吧: .AS2.0對(duì)XML的支持勉勉強(qiáng)強(qiáng),將就著可以用。而AS3.0中對(duì)XML的支持是全方位的,極其強(qiáng)大和靈活的
    2008-03-03
  • Actionscript 3.0中Singleton實(shí)現(xiàn) 修正篇

    Actionscript 3.0中Singleton實(shí)現(xiàn) 修正篇

    說(shuō)明:上一篇"一個(gè)簡(jiǎn)單的Actionscript的單態(tài)模式類"的實(shí)現(xiàn)在Actionscript中報(bào)錯(cuò),具體原因會(huì)在這篇Blog中詳細(xì)說(shuō)明。
    2009-02-02
  • 編寫(xiě)高效率的AS3代碼的小技巧

    編寫(xiě)高效率的AS3代碼的小技巧

    最近我研究了一些AS3代碼優(yōu)化的文章,一般都是集中在研究loops 和 Number types上的,本文不在重復(fù)類似的測(cè)試
    2009-02-02
  • AS3自寫(xiě)類整理筆記 ClassLoader類

    AS3自寫(xiě)類整理筆記 ClassLoader類

    在用flash做項(xiàng)目的時(shí)候,把一些元件,通過(guò)設(shè)置鏈接類,然后使用這個(gè)類,通過(guò)getClass方法即可把這個(gè)素材拿下來(lái)
    2008-06-06

最新評(píng)論