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

    将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"));

    转载于:https://www.cnblogs.com/lingLuoChengMi/p/10419238.html

  • 相关阅读:
    深入了解css的行高Line Height属性
    Kafka消息队列
    架构图
    清理肠道好方法
    维特根斯坦
    ES查询DSL大于小于写法
    python虚拟环境
    Dockerfile
    flask基本使用
    泛型类多个类型参数的定义
  • 原文地址:https://www.cnblogs.com/dt1991/p/15242582.html
Copyright © 2011-2022 走看看