1. 发
- var bin:ByteArray = new ByteArray();
- bin.writeMultiByte(strMsg, "utf-8");
- socket.writeShort(bin.length);
- socket.writeBytes(bin);
- socket.flush();
2. 收
- var length:uint = socket.readUnsignedShort();
- var ba:ByteArray=new ByteArray();
- socket.readBytes(ba,0,length);
- var str:String = ba.readUTFBytes(length);
二、erlang端( {packet,0} )
1. 收
- <<Len:16, Bindata2/binary>> = Bindata,
- Data = binary_to_list(Bindata2),
- gen_tcp:send(Socket,<<Len:16, BinData/binary>>),
文章来自: http://blog.csdn.net/skyman_2001/article/details/6624237