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


C# Network.NetPeer类代码示例

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


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

示例1: Main

		static void Main()
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			s_mainForm = new Form1();

			WriteToConsole("Type 'connect <host> <port>' to connect to another peer, or 'connect <port>' to connect to another localhost peer");

			NetConfiguration config = new NetConfiguration("p2pchat");
			config.MaxConnections = 256;
			s_peer = new NetPeer(config);
			//s_peer.VerboseLog = true;

			s_peer.SetMessageTypeEnabled(NetMessageType.ConnectionRejected | NetMessageType.BadMessageReceived | NetMessageType.VerboseDebugMessage, true);

			// start listening for incoming connections
			s_peer.Start();

			// create a buffer to read data into
			s_readBuffer = s_peer.CreateBuffer();

			Application.Idle += new EventHandler(OnAppIdle);
			Application.Run(s_mainForm);

			s_peer.Shutdown("Application exiting");
		}
开发者ID:zakvdm,项目名称:Frenetic,代码行数:26,代码来源:Program.cs

示例2: ShellCallback

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

示例3: Connection

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="manager">Local NetPeer</param>
        /// <param name="con">NetConnection</param>
        /// <param name="key">Encryption key</param>
        /// <param name="nodeId">Node Id</param>
        public Connection(NetPeer manager, NetConnection con, INetEncryption encryption, String nodeId)
        {
            // This keep alive timer is used to overcome BAD connections that drop ping/pong messages a lot.
            // It simply sends an empty message every five seconds. As long as some messages are retained
            // and received on the connection, all will be well
            _keepAliveTimer = new System.Timers.Timer(5000);
            _keepAliveTimer.Elapsed += new ElapsedEventHandler((Object state, ElapsedEventArgs args) =>
                this.SendMessage(this.NetManager.CreateMessage(0), NetDeliveryMethod.Unreliable));

            this.Username = (con.Tag as Handshake).Username;
            this.NetManager = manager;
            this.NetConnection = con;
            this.NetConnection.Tag = this;
            this.NodeId = nodeId;

            if (encryption != null)
            {
                _netEncryption = encryption;
            }
            else
            {
                // You could write code that makes it possible to transfer users between server
                // where you don't have any encryption key YET. The place to start that would
                // be here.
                this.IsTransfering = true;
                _netEncryption = new NetXtea(new Byte[16]);
            }

            // Not connected until everything is done.
            System.Threading.Thread.MemoryBarrier();

            _connected = true;
            _keepAliveTimer.Start();
        }
开发者ID:SleeplessByte,项目名称:lidgren-srp6a,代码行数:41,代码来源:Connection.cs

示例4: NetXtea

		/// <summary>
		/// 16 byte key
		/// </summary>
		public NetXtea(NetPeer peer, byte[] key, int rounds)
			: base(peer)
		{
			if (key.Length < c_keySize)
				throw new NetException("Key too short!");

			m_numRounds = rounds;
			m_sum0 = new uint[m_numRounds];
			m_sum1 = new uint[m_numRounds];
			uint[] tmp = new uint[8];

			int num2;
			int index = num2 = 0;
			while (index < 4)
			{
				tmp[index] = BitConverter.ToUInt32(key, num2);
				index++;
				num2 += 4;
			}
			for (index = num2 = 0; index < 32; index++)
			{
				m_sum0[index] = ((uint)num2) + tmp[num2 & 3];
				num2 += -1640531527;
				m_sum1[index] = ((uint)num2) + tmp[(num2 >> 11) & 3];
			}
		}
开发者ID:Alexz18z35z,项目名称:Gibbo2D,代码行数:29,代码来源:NetXteaEncryption.cs

示例5: NetCryptoProviderBase

		public NetCryptoProviderBase(NetPeer peer, SymmetricAlgorithm algo)
			: base(peer)
		{
			m_algorithm = algo;
			m_algorithm.GenerateKey();
			m_algorithm.GenerateIV();
		}
开发者ID:KennethYap,项目名称:MonoGame,代码行数:7,代码来源:NetCryptoProviderBase.cs

示例6: NetworkPeer

 /// <summary>
 /// Creates and starts a new NetworkPeer object, for servers.
 /// </summary>
 /// <param name="port">The port the server should listen on.</param>
 /// <param name="protocols">An array of messaging protocols.</param>
 public NetworkPeer(int port, params Protocol[] protocols)
 {
     Protocols = new List<Protocol>(protocols);
     netPeer = new NetPeer(new NetPeerConfiguration("N/A").GetStandardConfiguration(port));
     netPeer.RegisterReceivedCallback(OnMessageReceivedCallback);
     Start();
 }
开发者ID:dvgamer,项目名称:Touno.Sentinel-II,代码行数:12,代码来源:NetworkPeer.cs

示例7: Peer

        public Peer(NetPeer peer)
        {
            this.peer = peer;

            //start the client
            peer.Start();
        }
开发者ID:toshinto,项目名称:2dBattleground,代码行数:7,代码来源:Peer.cs

示例8: Program

        public Program()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            config.Port = API.MasterServer.MasterServerPort;

            peer = new NetPeer(config);
            peer.Start();
        }
开发者ID:imGoose,项目名称:SkyrimOnline,代码行数:9,代码来源:Program.cs

示例9: ToOutgoing

 internal NetOutgoingMessage ToOutgoing(NetPeer Sender)
 {
     NetOutgoingMessage msg = Sender.CreateMessage("__msg");
     StringBuilder sb = new StringBuilder();
     StringWriter writer = new StringWriter(sb);
     serializer.Serialize(writer, this);
     msg.Write(sb.ToString());
     return msg;
 }
开发者ID:hipolipolopigus,项目名称:SkyNet_Old,代码行数:9,代码来源:Packet.cs

示例10: OnLoginMessage

        public void OnLoginMessage(NetPeer server, NetBuffer buff, MessageBase msg)
        {
            var srv = server as NetServer;
            var im = buff as NetIncomingMessage;

            if (srv != null && im != null)
            {
                LoginMessageImpl(srv, im, msg);
            }
        }
开发者ID:ToraiRei,项目名称:cozy,代码行数:10,代码来源:Adventure.Callback.cs

示例11: OnLoginMessage

        public void OnLoginMessage(NetPeer client, NetBuffer buff, MessageBase msg)
        {
            var srv = client as NetClient;
            var im = buff as NetIncomingMessage;

            if (srv != null && im != null)
            {
                LoginResultMessageImpl(srv, im, msg);
            }
        }
开发者ID:xxy1991,项目名称:cozy,代码行数:10,代码来源:Form1.Callback.cs

示例12: Main

        static void Main(string[] args)
        {
            NetPeerConfiguration config = new NetPeerConfiguration("unittests");
            config.EnableUPnP = true;
            NetPeer peer = new NetPeer(config);
            peer.Start(); // needed for initialization

            Console.WriteLine("Unique identifier is " + NetUtility.ToHexString(peer.UniqueIdentifier));

            ReadWriteTests.Run(peer);

            NetQueueTests.Run();

            MiscTests.Run(peer);

            BitVectorTests.Run();

            EncryptionTests.Run(peer);

            var om = peer.CreateMessage();
            peer.SendUnconnectedMessage(om, new IPEndPoint(IPAddress.Loopback, 14242));
            try
            {
                peer.SendUnconnectedMessage(om, new IPEndPoint(IPAddress.Loopback, 14242));
            }
            catch (NetException nex)
            {
                if (nex.Message != "This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently")
                    throw nex;
            }

            peer.Shutdown("bye");

            // read all message
            NetIncomingMessage inc = peer.WaitMessage(5000);
            while (inc != null)
            {
                switch (inc.MessageType)
                {
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.ErrorMessage:
                        Console.WriteLine("Peer message: " + inc.ReadString());
                        break;
                    case NetIncomingMessageType.Error:
                        throw new Exception("Received error message!");
                }

                inc = peer.ReadMessage();
            }

            Console.WriteLine("Done");
            Console.ReadKey();
        }
开发者ID:JamieH,项目名称:lidgren-network-gen3,代码行数:55,代码来源:Program.cs

示例13: PeerListener

        public void PeerListener(NetPeer peer)
        {
            
            while (true)
            {
                NetIncomingMessage msg;
                while ((msg=peer.ReadMessage())!=null)
                {
                    NetConnection connection = msg.SenderConnection;

                    switch (msg.MessageType)
                    {
                      
                        case NetIncomingMessageType.StatusChanged:
                            switch (msg.SenderConnection.Status)
                            {    
                                case NetConnectionStatus.Connected:
                                    logger.Info("{0}: connected",connection.RemoteEndPoint.Address.ToString());
                                    ExecuteCommand(new CmdInitOk(connection));
                                    break;
                                case NetConnectionStatus.Disconnected:
                                    logger.Info("{0}: disconnected", connection.RemoteEndPoint.Address.ToString());
                                    break;
                                case NetConnectionStatus.Disconnecting:
                                    logger.Info("{0}: disconnecting", connection.RemoteEndPoint.Address.ToString());
                                    break;
                                    
                                                                                                     
                            }
                            break;
                    
                        case NetIncomingMessageType.Data:
                            msg.Decrypt(new NetRC2Encryption(peer, connection.CryptoKey));  
                            string[] OpData = msg.ReadString().Split('&');
                            var OpCode = (LoginOperation)Enum.Parse(typeof(LoginOperation), OpData[0]);

                            switch (OpCode)
                            {                                
                                case LoginOperation.AuthLog:   
                                    string[] authData = OpData[1].Split('#');
                                    string login = authData[0];
                                    string pass = authData[1];
                                    ExecuteCommand(new CmdLoginOkFail(connection, login,pass));
                                    break;
                            }


                            break;                    
                    }

                    peer.Recycle(msg);
                }
            }

        }
开发者ID:Aslan125,项目名称:GameNet,代码行数:55,代码来源:LoginCmdInvoker.cs

示例14: Host

        public void Host()
        {
            // Create server and tell it to start listening for connections.
            Config.Port = 25000;
            NetServer server = new NetServer(Config);
            server.Start();
            // Assign it to NetPeer so it can be used interchangibly with client.
            Peer = server;

            Console.WriteLine("Server has started.");
        }
开发者ID:Gevil,项目名称:Projects,代码行数:11,代码来源:NetworkManager.cs

示例15: Start

        public void Start()
        {
            peer = new NetPeer(config);
            peer.Start();
            localIdentifier = peer.UniqueIdentifier;

            listener = new peerListener(peer, localIdentifier);
            moveQueue = new Queue<string>();

            NetThread = new Thread(new ThreadStart(listener.processNetwork));
            NetThread.Start();
        }
开发者ID:bradleypaul,项目名称:Kulami,代码行数:12,代码来源:kulamiPeer.cs


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