当前位置: 首页>>代码示例>>C#>>正文


C# Network.NetBuffer类代码示例

本文整理汇总了C#中Lidgren.Network.NetBuffer的典型用法代码示例。如果您正苦于以下问题:C# NetBuffer类的具体用法?C# NetBuffer怎么用?C# NetBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NetBuffer类属于Lidgren.Network命名空间,在下文中一共展示了NetBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoSendDiscoveryRequest

        internal void DoSendDiscoveryRequest(
            IPEndPoint endPoint,
            bool useBroadcast,
            NetDiscoveryRequest request,
            float interval,
            float timeout)
        {
            if (!m_netBase.m_isBound)
                m_netBase.Start();

            if (request == null)
            {
                m_netBase.LogVerbose("Creating discovery request " + m_nextRequestNumber);
                request = new NetDiscoveryRequest(endPoint, m_nextRequestNumber++, useBroadcast, interval, timeout);
                if (m_requests == null)
                    m_requests = new List<NetDiscoveryRequest>();
                m_requests.Add(request);
            }

            string appIdent = m_netBase.m_config.ApplicationIdentifier;
            NetBuffer data = new NetBuffer(appIdent.Length + 8);

            // write app identifier
            data.Write(appIdent);

            // write netbase identifier to avoid self-discovery
            data.Write(m_netBase.m_randomIdentifier);

            // write request number
            data.Write((ushort)request.Number);

            m_netBase.LogWrite("Discovering " + endPoint.ToString() + "...");
            m_netBase.QueueSingleUnreliableSystemMessage(NetSystemType.Discovery, data, endPoint, useBroadcast);
        }
开发者ID:kindex,项目名称:labyrinth2,代码行数:34,代码来源:NetDiscovery.cs

示例2: HandleMessage

		private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
		{
			switch (type)
			{
				case NetMessageType.StatusChanged:
					if (source.LocalHailData == null)
						source.LocalHailData = Encoding.ASCII.GetBytes("Hi; I'm " + s_peer.GetHashCode());
					if (source.RemoteHailData != null)
						WriteToConsole("New status: " + source.Status + " - remote hail is: " + Encoding.ASCII.GetString(source.RemoteHailData));
					else
						WriteToConsole("New status: " + source.Status + " - remote hail is null");
					break;
				case NetMessageType.DebugMessage:
				case NetMessageType.VerboseDebugMessage:
				case NetMessageType.BadMessageReceived:
				case NetMessageType.ConnectionRejected:
					WriteToConsole(buffer.ReadString());
					break;
				case NetMessageType.Data:
					WriteToConsole(source.RemoteEndpoint + " writes: " + buffer.ReadString());
					break;
				case NetMessageType.ServerDiscovered:
					// discovered another peer!
					s_peer.Connect(buffer.ReadIPEndPoint(), Encoding.ASCII.GetBytes("Hi; I'm " + s_peer.GetHashCode()));
					break;
				default:
					// unhandled
					break;
			}
		}
开发者ID:zakvdm,项目名称:Frenetic,代码行数:30,代码来源:Program.cs

示例3: receive

        private void receive()
        {
            NetBuffer buffer = new NetBuffer();

            bool keepGoing = true;
            while (keepGoing)
            {
                NetIncomingMessage message;
                while ((message = client.ReadMessage()) != null)
                {
                    switch (message.MessageType)
                    {
                        case NetIncomingMessageType.DebugMessage:
                            Console.WriteLine(buffer.ReadString());
                            break;

                        case NetIncomingMessageType.StatusChanged:
                            Console.WriteLine("New status: " + client.Status + " (Reason: " + buffer.ReadString() + ")");
                            if(client.Status != NetPeerStatus.Running)
                            {
                                keepGoing = false;
                                break;
                            }
                            break;

                        case NetIncomingMessageType.Data:
                            // Handle data in buffer here
                            break;
                    }
                }
            }
        }
开发者ID:CheeseSoftware,项目名称:RTS-test,代码行数:32,代码来源:ClientConnection.cs

示例4: ShellCallback

 public static void ShellCallback(MessageBase msg, NetBuffer buff)
 {
     if(CallbackMapping.ContainsKey(msg.Id))
     {
         CallbackMapping[msg.Id](buff, msg);
     }
 }
开发者ID:xxy1991,项目名称:cozy,代码行数:7,代码来源:MessageCallbackManager.cs

示例5: HandleMessage

        private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
        {
            switch (type)
            {
                case NetMessageType.DebugMessage:
                    WriteToConsole(buffer.ReadString());
                    break;
                case NetMessageType.StatusChanged:
                    WriteToConsole("New status: " + source.Status + " (" + buffer.ReadString() + ")");
                    UpdateStatisticsDisplay(source);
                    break;
                case NetMessageType.Data:
                    //System.IO.File.AppendAllText("C:\\receivedpackets.txt", s_userMessagesReceived.ToString() + ": " + msg.ReadString() + " (" + msg.m_sequenceNumber + ")" + Environment.NewLine);
                    s_userMessagesReceived++;

                    // simulate some processing of the message here
                    for (int i = 0; i < buffer.LengthBytes - 2; i++)
                        buffer.ReadByte();

                    // check checksum
                    ushort checksum = NetChecksum.Adler16(buffer.Data, 0, buffer.LengthBytes - 2);
                    ushort given = buffer.ReadUInt16();
                    if (checksum != given)
                        WriteToConsole("Wrong checksum! Expected " + checksum + " found given " + given);

                    double b = s_userMessagesReceived;
                    for (int i = 0; i < 1000; i++)
                        b += Math.Sqrt((double)i) / Math.Sin(s_tmp);
                    s_tmp += b / 10000.0;
                    break;
                default:
                    break;
            }
        }
开发者ID:JeffM2501,项目名称:HackSharp,代码行数:34,代码来源:Program.cs

示例6: ReadMessage

 public bool ReadMessage(NetBuffer intoBuffer, out NetMessageType type, out INetConnection sender)
 {
     NetConnection senderInternal;
     bool messageExists = _netServer.ReadMessage(intoBuffer, out type, out senderInternal);
     sender = new NetConnectionWrapper(senderInternal);
     return messageExists;
 }
开发者ID:zakvdm,项目名称:Frenetic,代码行数:7,代码来源:NetServerWrapper.cs

示例7: ClientCommand

        bool ClientCommand(client_t cl, NetBuffer msg)
        {
            int seq = msg.ReadInt32();
            string s = msg.ReadString();

            // see if we have already executed it
            if (cl.lastClientCommand >= seq)
                return true;

            Common.Instance.WriteLine("ClientCommand: {0}[s{1}]: {2}", cl.name, seq, s);

            // drop the connection if we have somehow lost commands
            if (seq > cl.lastClientCommand + 1)
            {
                Common.Instance.WriteLine("Client {0} lost {1} clientCommands", cl.name, seq-cl.lastClientCommand+1);
                DropClient(cl, "Lost reliable commands");
                return false;
            }

            // don't allow another command for one second
            cl.nextReliableTime = (int)time + 1000;

            ExecuteClientCommand(cl, s);
            cl.lastClientCommand = seq;
            cl.lastClientCommandString = s;
            return true;    // continue procesing
        }
开发者ID:maesse,项目名称:CubeHags,代码行数:27,代码来源:ServerClient.cs

示例8: NetBase

        protected NetBase(NetConfiguration config)
        {
            Debug.Assert(config != null, "Config must not be null");
            if (string.IsNullOrEmpty(config.ApplicationIdentifier))
                throw new ArgumentException("Must set ApplicationIdentifier in NetConfiguration!");
            m_config = config;
            m_receiveBuffer = new NetBuffer(config.ReceiveBufferSize);
            m_sendBuffer = new NetBuffer(config.SendBufferSize);
            m_senderRemote = (EndPoint)new IPEndPoint(IPAddress.Any, 0);
            m_statistics = new NetBaseStatistics();
            m_receivedMessages = new NetQueue<IncomingNetMessage>(4);
            m_scratchBuffer = new NetBuffer(32);
            m_bindLock = new object();
            m_discovery = new NetDiscovery(this);

            m_randomIdentifier = new byte[8];
            NetRandom.Instance.NextBytes(m_randomIdentifier);

            m_unsentOutOfBandMessages = new NetQueue<NetBuffer>();
            m_unsentOutOfBandRecipients = new NetQueue<IPEndPoint>();
            m_susmQueue = new Queue<SUSystemMessage>();

            // default enabled message types
            m_enabledMessageTypes =
                NetMessageType.Data | NetMessageType.StatusChanged | NetMessageType.ServerDiscovered |
                NetMessageType.DebugMessage | NetMessageType.Receipt;
        }
开发者ID:kindex,项目名称:labyrinth2,代码行数:27,代码来源:NetBase.cs

示例9: StatusChangeHandler

        public static void StatusChangeHandler(NetClient client, NetBuffer buffer)
        {
            string status_msg = buffer.ReadString();
            NetConnectionStatus status = (NetConnectionStatus)buffer.ReadByte();

            if (status == NetConnectionStatus.Connected)
            {
                Console.WriteLine("Client: Connected");

                Console.Write("Client: Starting IOS");

                int i;
                for (i = 0; i < 10; i++)
                {
                    Console.Write(".");
                    Thread.Sleep(500);
                }
                Console.WriteLine("");

                //Show the IOS Master form
                System.Windows.Forms.Application.EnableVisualStyles();
                System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
                System.Windows.Forms.Application.Run(new MasterForm());
            }

            if (status == NetConnectionStatus.Disconnected)
            {
                Console.WriteLine("Client: Disconnected - " + status_msg);
            }
        }
开发者ID:rcrowe,项目名称:ees_xplane,代码行数:30,代码来源:EventHandler.cs

示例10: fireClientApproval

 public void fireClientApproval(NetServer server, NetBuffer buffer, NetConnection sender)
 {
     if (ClientApproval != null)
     {
         ClientApproval(server, buffer, sender);
     }
 }
开发者ID:rcrowe,项目名称:ees_xplane,代码行数:7,代码来源:NetworkEvents.cs

示例11: fireDataRecieved

 public void fireDataRecieved(NetClient client, NetBuffer buffer)
 {
     if (DataRecieved != null)
     {
         DataRecieved(client, buffer);
     }
 }
开发者ID:rcrowe,项目名称:ees_xplane,代码行数:7,代码来源:NetworkEvents.cs

示例12: fireStatusChanged

 public void fireStatusChanged(NetServer server, NetBuffer buffer, NetConnection sender)
 {
     if (StatusChanged != null)
     {
         StatusChanged(server, buffer, sender);
     }
 }
开发者ID:rcrowe,项目名称:ees_xplane,代码行数:7,代码来源:NetworkEvents.cs

示例13: fireConnectionRejected

 public void fireConnectionRejected(NetClient client, NetBuffer buffer)
 {
     if (ConnectionRejected != null)
     {
         ConnectionRejected(client, buffer);
     }
 }
开发者ID:rcrowe,项目名称:ees_xplane,代码行数:7,代码来源:NetworkEvents.cs

示例14: Write

 public void Write(NetBuffer om)
 {
     if (MetaData == null) MetaData = "Null";
     om.Write(MetaData);
     om.Write(Data.Length);
     om.Write(Data);
 }
开发者ID:xxy1991,项目名称:cozy,代码行数:7,代码来源:BinaryPacketMessage.cs

示例15: Process

        public static void Process(NetServer server, NetBuffer buffer, NetConnection sender)
        {
            Config config = Config.Instance;

            List<NetConnection> connections = server.Connections;

            //Lets send that message onto any plugin clients
            foreach (NetConnection connection in connections)
            {
                if (config.Server.client_connections.ContainsKey(connection.RemoteEndpoint.ToString()))
                {
                    string client_type = (string)config.Server.client_connections[connection.RemoteEndpoint.ToString()];

                    if (client_type.ToLower() == "plugin")
                    {
                        string msg = buffer.ReadString();

                        Console.WriteLine("Slave: Data sent - " + msg);

                        NetBuffer slavebuf = server.CreateBuffer();

                        slavebuf.Write(msg);

                        server.SendMessage(slavebuf, connection, NetChannel.ReliableInOrder4);
                    }
                }
            }
        }
开发者ID:rcrowe,项目名称:ees_xplane,代码行数:28,代码来源:SlaveHandler.cs


注:本文中的Lidgren.Network.NetBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。