一、as端
1. 发

  1. var bin:ByteArray = new ByteArray();
  2. bin.writeMultiByte(strMsg, "utf-8");
  3. socket.writeShort(bin.length);
  4. socket.writeBytes(bin);
  5. socket.flush();

2. 收

  1. var length:uint = socket.readUnsignedShort();     
  2. var ba:ByteArray=new ByteArray();
  3. socket.readBytes(ba,0,length);
  4. var str:String = ba.readUTFBytes(length);

二、erlang端( {packet,0} )
1. 收

  1. <<Len:16, Bindata2/binary>> = Bindata,
  2. Data = binary_to_list(Bindata2),
2. 发


  1. gen_tcp:send(Socket,<<Len:16, BinData/binary>>),


文章来自: http://blog.csdn.net/skyman_2001/article/details/6624237






10-18 02:32