Esempio n. 1
0
    protected override void SetActionHead(NetWriter writer)
    {
        //todo 启用自定的结构
        package headPack = new package()
        {
            session   = Head.MsgId,
            protoId   = ActionId,
            errorcode = 0,
        };

        byte[] data = headPack.encode();
        writer.SetHeadBuffer(data);
        writer.SetBodyData(null);
    }
Esempio n. 2
0
    private static void Send(SprotoTypeBase rpc, long?session, int tag)
    {
        if (!bConnected || !Enabled)
        {
            return;
        }

        package pkg = new package();

        pkg.type = tag;

        if (session != null)
        {
            pkg.session = (long)session;
            sessionDict.Add((long)session, protocol[tag].Response.Value);
        }

        sendStream.Seek(0, SeekOrigin.Begin);
        int len = pkg.encode(sendStream);

        if (rpc != null)
        {
            len += rpc.encode(sendStream);
        }

        byte[] data = sendPack.pack(sendStream.Buffer, len);
        if (data.Length > MAX_PACK_LEN)
        {
            Debug.Log("data.Length > " + MAX_PACK_LEN + " => " + data.Length);
            return;
        }

        sendStream.Seek(0, SeekOrigin.Begin);
        sendStream.WriteByte((byte)(data.Length >> 8));
        sendStream.WriteByte((byte)data.Length);
        sendStream.Write(data, 0, data.Length);

        try {
            socket.Send(sendStream.Buffer, sendStream.Position, SocketFlags.None);
        }
        catch (Exception e) {
            Debug.Log("send Lost network" + ((SocketException)e).ErrorCode);
            Debug.Log("send Lost network" + ((SocketException)e).ToString());
            Debug.LogWarning(e.ToString());
        }
    }