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


C# NetMessageType类代码示例

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


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

示例1: HandleMessage

 private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
 {
     switch (type)
     {
         case NetMessageType.DebugMessage:
             Console.WriteLine(buffer.ReadString());
             break;
         case NetMessageType.StatusChanged:
             NetConnectionStatus status = source.Status;
             if (status == NetConnectionStatus.Connected)
             {
                 source.Tag = ImageClientStatus.JustConnected;
                 s_nextPixelToSend[source] = 0;
             }
             else if (status == NetConnectionStatus.Disconnected)
             {
                 if (s_nextPixelToSend.ContainsKey(source))
                     s_nextPixelToSend.Remove(source);
             }
             break;
         case NetMessageType.Receipt:
             source.Tag = ImageClientStatus.Running;
             break;
         default:
             // unhandled
             break;
     }
 }
开发者ID:JeffM2501,项目名称:HackSharp,代码行数:28,代码来源:Program.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: 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

示例4: Reset

		internal void Reset()
		{
			m_messageType = NetMessageType.LibraryError;
			m_bitLength = 0;
			m_isSent = false;
			NetException.Assert(m_recyclingCount == 0);
			m_fragmentGroup = 0;
		}
开发者ID:Aslan125,项目名称:GameNet,代码行数:8,代码来源:NetOutgoingMessage.cs

示例5: Reset

		internal void Reset()
		{
			m_messageType = NetMessageType.LibraryError;
			m_bitLength = 0;
			m_isSent = false;
			m_recyclingCount = 0;
			m_fragmentGroup = 0;
		}
开发者ID:Indiefreaks,项目名称:igf,代码行数:8,代码来源:NetOutgoingMessage.cs

示例6: NetMessage

 //private Byte[] recBuffer;
 
 public NetMessage()
 {
     type = NetMessageType.NONE;
     m_terminalID = "";
     clientID = -1;
     //bytes = 0;
     msg = String.Empty;
     //recBuffer = new Byte[256];
 }
开发者ID:wshanshan,项目名称:DDD,代码行数:11,代码来源:NetworkTools.cs

示例7: Reset

		internal void Reset()
		{
			m_incomingMessageType = NetIncomingMessageType.Error;
			m_readPosition = 0;
			m_receivedMessageType = NetMessageType.LibraryError;
			m_senderConnection = null;
			m_bitLength = 0;
			m_isFragment = false;
		}
开发者ID:xxy1991,项目名称:cozy,代码行数:9,代码来源:NetIncomingMessage.cs

示例8: AddMessageHandler

 public void AddMessageHandler(NetMessageType messageType , Action<NetMessageType, NetIncomingMessage> handler)
 {
     if(!messagehandler.ContainsKey(messageType))
     {
         messagehandler[messageType] = new List<Action<NetMessageType,NetIncomingMessage>>();
         messagehandler[messageType].Add(handler);
     }
     else
     {
            messagehandler[messageType].Add(handler);
     }
 }
开发者ID:brunoduartec,项目名称:port-ploobsengine,代码行数:12,代码来源:NetworkCliente.cs

示例9: ReceivedSequencedMessage

		// returns true if message should be rejected
		internal bool ReceivedSequencedMessage(NetMessageType mtp, ushort seqNr)
		{
			int slot = (int)mtp - (int)NetMessageType.UserSequenced;

			int diff = Relate(seqNr, m_lastReceivedSequenced[slot]);

			if (diff == 0)
				return true; // reject; already received
			if (diff > (ushort.MaxValue / 2))
				return true; // reject; out of window

			m_lastReceivedSequenced[slot] = seqNr;
			return false;
		}
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:15,代码来源:NetConnection.Reliability.cs

示例10: GetSendSequenceNumber

		internal ushort GetSendSequenceNumber(NetMessageType mtp)
		{
			if (mtp < NetMessageType.UserSequenced)
				return 0;

			int slot = (int)mtp - (int)NetMessageType.UserSequenced;
			int retval;
			lock (m_nextSendSequenceNumber)
			{
				retval = m_nextSendSequenceNumber[slot];
				if (retval == ushort.MaxValue)
					retval = -1;
				m_nextSendSequenceNumber[slot] = retval + 1;
			}
			return (ushort)retval;
		}
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:16,代码来源:NetConnection.Reliability.cs

示例11: RecieveCreateNetworkObjectOnServer

        void RecieveCreateNetworkObjectOnServer(NetMessageType NetMessageType, NetIncomingMessage NetIncomingMessage)
        {
            String ident = NetIncomingMessage.ReadString();
            if (NetWorkObjects.ContainsKey(ident))
            {
                ServerIObject obj = NetWorkObjects[ident].CreateLoadObjectOrder(NetIncomingMessage);
                world.AddObject(obj);

                //skip the message type                
                NetIncomingMessage.Position = sizeof(short) * 8;

                NetOutgoingMessage o = CreateMessage(NetWorking.NetMessageType.CreateNetworkObjectOnClient);
                o.Write(obj.GetId());
                NetOutgoingMessage mes = NetWorkObjects[ident].CreateRedistributeOrder(obj, NetIncomingMessage, o);
                this.SendMessageToAllClients(mes,NetDeliveryMethod.ReliableOrdered);
            }
        }
开发者ID:brunoduartec,项目名称:port-ploobsengine,代码行数:17,代码来源:NetworkServer.cs

示例12: HandleEchoMessage

        void HandleEchoMessage(NetMessageType NetMessageType, NetIncomingMessage NetIncomingMessage)
        {
            String ident = NetIncomingMessage.ReadString();
            long unique = NetIncomingMessage.ReadInt64();

            if(NetWorkEcho.ContainsKey(ident))
            {
                NetOutgoingMessage o = CreateMessage(NetWorking.NetMessageType.Echo);
                o.Write(ident);
                o.Write(unique);
                SendMessageToAllClients(NetWorkEcho[ident].AnswerMessage(NetIncomingMessage,o),NetDeliveryMethod.ReliableOrdered);
            }
        }    
开发者ID:brunoduartec,项目名称:port-ploobsengine,代码行数:13,代码来源:NetworkServer.cs

示例13: CreateMessage

 public NetOutgoingMessage CreateMessage(NetMessageType messageType)
 {
     NetOutgoingMessage mes = server.CreateMessage();
     mes.Write((short)messageType);
     return mes;
 }
开发者ID:brunoduartec,项目名称:port-ploobsengine,代码行数:6,代码来源:NetworkServer.cs

示例14: ReceivedUnconnectedLibraryMessage

		private void ReceivedUnconnectedLibraryMessage(double now, IPEndPoint senderEndpoint, NetMessageType tp, int ptr, int payloadByteLength)
		{
			NetConnection shake;
			if (m_handshakes.TryGetValue(senderEndpoint, out shake))
			{
				shake.ReceivedHandshake(now, tp, ptr, payloadByteLength);
				return;
			}

			//
			// Library message from a completely unknown sender; lets just accept Connect
			//
			switch (tp)
			{
				case NetMessageType.Discovery:
					if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryRequest))
					{
						NetIncomingMessage dm = CreateIncomingMessage(NetIncomingMessageType.DiscoveryRequest, payloadByteLength);
						if (payloadByteLength > 0)
							Buffer.BlockCopy(m_receiveBuffer, ptr, dm.m_data, 0, payloadByteLength);
						dm.m_receiveTime = now;
						dm.m_bitLength = payloadByteLength * 8;
						dm.m_senderEndpoint = senderEndpoint;
						ReleaseMessage(dm);
					}
					return;

				case NetMessageType.DiscoveryResponse:
					if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryResponse))
					{
						NetIncomingMessage dr = CreateIncomingMessage(NetIncomingMessageType.DiscoveryResponse, payloadByteLength);
						if (payloadByteLength > 0)
							Buffer.BlockCopy(m_receiveBuffer, ptr, dr.m_data, 0, payloadByteLength);
						dr.m_receiveTime = now;
						dr.m_bitLength = payloadByteLength * 8;
						dr.m_senderEndpoint = senderEndpoint;
						ReleaseMessage(dr);
					}
					return;
				case NetMessageType.NatIntroduction:
					HandleNatIntroduction(ptr);
					return;
				case NetMessageType.NatPunchMessage:
					HandleNatPunch(ptr, senderEndpoint);
					return;
				case NetMessageType.Connect:
					// proceed
					break;
				case NetMessageType.Disconnect:
					// this is probably ok
					LogVerbose("Received Disconnect from unconnected source: " + senderEndpoint);
					return;
				default:
					LogWarning("Received unhandled library message " + tp + " from " + senderEndpoint);
					return;
			}

			// It's someone wanting to shake hands with us!

			int reservedSlots = m_handshakes.Count + m_connections.Count;
			if (reservedSlots >= m_configuration.m_maximumConnections)
			{
				// server full
				NetOutgoingMessage full = CreateMessage("Server full");
				full.m_messageType = NetMessageType.Disconnect;
				SendLibrary(full, senderEndpoint);
				return;
			}

			// Ok, start handshake!
			NetConnection conn = new NetConnection(this, senderEndpoint);
			m_handshakes.Add(senderEndpoint, conn);
			conn.ReceivedHandshake(now, tp, ptr, payloadByteLength);

			return;
		}
开发者ID:Dahie,项目名称:September-1983,代码行数:76,代码来源:NetPeer.Internal.cs

示例15: ReceivedUnconnectedLibraryMessage

		private void ReceivedUnconnectedLibraryMessage(double now, IPEndPoint senderEndpoint, NetMessageType tp, int ptr, int payloadByteLength)
		{
			NetConnection shake;
			if (m_handshakes.TryGetValue(senderEndpoint, out shake))
			{
				shake.ReceivedHandshake(now, tp, ptr, payloadByteLength);
				return;
			}

			//
			// Library message from a completely unknown sender; lets just accept Connect
			//
			switch (tp)
			{
				case NetMessageType.Discovery:
					HandleIncomingDiscoveryRequest(now, senderEndpoint, ptr, payloadByteLength);
					return;
				case NetMessageType.DiscoveryResponse:
					HandleIncomingDiscoveryResponse(now, senderEndpoint, ptr, payloadByteLength);
					return;
				case NetMessageType.NatIntroduction:
					HandleNatIntroduction(ptr);
					return;
				case NetMessageType.NatPunchMessage:
					HandleNatPunch(ptr, senderEndpoint);
					return;
				case NetMessageType.ConnectResponse:

					lock (m_handshakes)
					{
						foreach (var hs in m_handshakes)
						{
							if (hs.Key.Address.Equals(senderEndpoint.Address))
							{
								if (hs.Value.m_connectionInitiator)
								{
									//
									// We are currently trying to connection to XX.XX.XX.XX:Y
									// ... but we just received a ConnectResponse from XX.XX.XX.XX:Z
									// Lets just assume the router decided to use this port instead
									//
									var hsconn = hs.Value;
									m_connectionLookup.Remove(hs.Key);
									m_handshakes.Remove(hs.Key);

									LogDebug("Detected host port change; rerouting connection to " + senderEndpoint);
									hsconn.MutateEndpoint(senderEndpoint);

									m_connectionLookup.Add(senderEndpoint, hsconn);
									m_handshakes.Add(senderEndpoint, hsconn);

									hsconn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
									return;
								}
							}
						}
					}

					LogWarning("Received unhandled library message " + tp + " from " + senderEndpoint);
					return;
				case NetMessageType.Connect:
					// proceed
					break;
				case NetMessageType.Disconnect:
					// this is probably ok
					LogVerbose("Received Disconnect from unconnected source: " + senderEndpoint);
					return;
				default:
					LogWarning("Received unhandled library message " + tp + " from " + senderEndpoint);
					return;
			}

			// It's someone wanting to shake hands with us!

			int reservedSlots = m_handshakes.Count + m_connections.Count;
			if (reservedSlots >= m_configuration.m_maximumConnections)
			{
				// server full
				NetOutgoingMessage full = CreateMessage("Server full");
				full.m_messageType = NetMessageType.Disconnect;
				SendLibrary(full, senderEndpoint);
				return;
			}

			// Ok, start handshake!
			NetConnection conn = new NetConnection(this, senderEndpoint);
			m_handshakes.Add(senderEndpoint, conn);
			conn.ReceivedHandshake(now, tp, ptr, payloadByteLength);

			return;
		}
开发者ID:nelak2,项目名称:Demiurge,代码行数:91,代码来源:NetPeer.Internal.cs


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