Exemplo n.º 1
0
        protected override int DoSend(NetworkMessageItem item)
        {
            var send    = 0;
            var msgItem = item as VNetworkMessageItem;

            if (null == msgItem)
            {
                Logger.ErrorFormat("message item is null or not VNetworkMessageItem {0}", IdInfo());
                return(send);
            }


            switch (msgItem.Channel)
            {
            case RealTimeChannel:
                if (null == RealTimePeer)
                {
                    Logger.ErrorFormat("{0} send failed : peer is null", IdInfo());
                    return(send);
                }
                _stopwatch.Reset();
                long l = item.MemoryStream.Length;
                item.MemoryStream.Seek(0, SeekOrigin.Begin);
                item.MemoryStream.WriteByte((byte)(RemoteConnId >> 0));
                item.MemoryStream.WriteByte((byte)(RemoteConnId >> 8));
                item.MemoryStream.WriteByte((byte)(RemoteConnId >> 16));
                item.MemoryStream.WriteByte((byte)(RemoteConnId >> 24));

                if (item.MemoryStream.Capacity < item.MemoryStream.Length + 4)
                {
                    item.MemoryStream.Capacity = item.MemoryStream.Capacity + 4;
                }
                send = (int)item.MemoryStream.Length;
                RealTimePeer.Send(item.MemoryStream.GetBuffer(), (int)item.MemoryStream.Length, 0);

                _stopwatch.Stop();
                FlowSend(false, l, _stopwatch.ElapsedMilliseconds);
                break;

            case ReliableChannel:
                _stopwatch.Reset();
                send = (int)item.MemoryStream.Length;
                RealiableConn.Send(item.MemoryStream.GetBuffer(), (int)item.MemoryStream.Length - 4, 4);
                _stopwatch.Stop();
                FlowSend(true, item.MemoryStream.Length, _stopwatch.ElapsedMilliseconds);
                break;
            }

            return(send);
        }
Exemplo n.º 2
0
        protected override void DoSend(NetworkMessageItem item)
        {
            var msgItem = item as VNetworkMessageItem;

            if (null == msgItem)
            {
                Logger.ErrorFormat("message item is null or not VNetworkMessageItem {0}", IdInfo());
                return;
            }

            switch (msgItem.Channel)
            {
            case RealTimeChannel:
                if (null == RealTimePeer)
                {
                    Logger.ErrorFormat("{0} send failed : peer is null", IdInfo());
                    return;
                }
                _stopwatch.Reset();
                long l = item.MemoryStream.Length;
                item.MemoryStream.Seek(0, SeekOrigin.Begin);
                item.MemoryStream.Write(BitConverter.GetBytes(RemoteConnId), 0, 4);

                RealTimePeer.Send(item.MemoryStream.GetBuffer(), (int)item.MemoryStream.Length, 0);

                _stopwatch.Stop();
                FlowSend(false, l, _stopwatch.ElapsedMilliseconds);
                break;

            case ReliableChannel:
                _stopwatch.Reset();
                RealiableConn.Send(item.MemoryStream.GetBuffer(), (int)item.MemoryStream.Length - 4, 4);
                _stopwatch.Stop();
                FlowSend(true, item.MemoryStream.Length, _stopwatch.ElapsedMilliseconds);
                break;
            }
        }
Exemplo n.º 3
0
 public void SendRawDataRealTime(byte[] bytes, int length, int offset)
 {
     RealTimePeer.Send(bytes, length, offset);
 }