zoukankan      html  css  js  c++  java
  • as3 tcpSocket发送HEX数据

    将string转为HEX

    function tenToHexFunc(_info:String):ByteArray{
                
                _info=_info.split(" ").join("");//删除所有的空格
                
                var byte:ByteArray = new ByteArray();
                    for (var i:uint = 0; i < _info.length; i = i + 2)
                    {
                        //trace(i);
                        byte.writeByte(uint("0x" + _info.substr(i, 2)))
                        trace(_info.substr(i, 2));
                    }
                    //writeBytes(byte)
                
                
                return byte;
            }

    然后将转好的HEX数据发送给服务端

    //向服务端发送HEX数据
            public function sendHEXFunc(msg:ByteArray):void
            {
                try
                {
                    if( _client != null && _client.connected )
                    {
                        _client.writeBytes(msg);
                        _client.flush(); 
                        //log( "Sent message to " + clientSocket.remoteAddress + ":" + clientSocket.remotePort );
                    }
                    else log("No socket connection.");
                    if(!_client.connected){
                        _client=null;
                        collect(clientHost,clientPort);
                        _client.writeBytes(msg);
                        _client.flush();
                    }
                }
                catch ( error:Error )
                {
                    log( error.message );
                    
                }
            }

    发送的调用方法如下

    tcpClient.sendHEXFunc(tenToHexFunc("aa ff ff 1b 01 cc bf 28"));
  • 相关阅读:
    02-MySQL的安装和管理
    01-pymysql模块的安装
    异常处理
    USACO 2015 Feb Censoring
    玄武密码(bzoj4327)(JSOI2012)
    浅谈AC自动机
    Equation
    JOI五子棋
    浅谈Tarjan
    年轮蛋糕JOI2014Final
  • 原文地址:https://www.cnblogs.com/lingLuoChengMi/p/10419238.html
Copyright © 2011-2022 走看看