• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Network.NetPeer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: HandleMessage

        protected override bool HandleMessage(NetPeer peer, NetIncomingMessage msg)
        {
            switch (msg.MessageType)
            {
                case NetIncomingMessageType.DiscoveryResponse:
                {
                    PostNotificationImmediately(NetworkNotifications.LocalServerDiscovered, msg);
                    return true;
                }
            }

            return false;
        }
开发者ID:bbqchickenrobot,项目名称:atomic-bomberman-xna,代码行数:13,代码来源:LocalServersDiscovery.cs


示例17: NetPeerSettingsWindow

        public NetPeerSettingsWindow(string title, NetPeer peer)
        {
            Peer = peer;
            InitializeComponent();
            RefreshData();
            this.Text = title;

            // auto refresh now and then
            timer = new Timer();
            timer.Interval = 250;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Enabled = true;
        }
开发者ID:ChrizBonex,项目名称:RaspberryEngine,代码行数:13,代码来源:NetPeerSettingsWindow.cs


示例18: NetConnection

 internal NetConnection(NetPeer peer, IPEndPoint remoteEndpoint)
 {
     m_peer = peer;
     m_peerConfiguration = m_peer.Configuration;
     m_status = NetConnectionStatus.None;
     m_visibleStatus = NetConnectionStatus.None;
     m_remoteEndpoint = remoteEndpoint;
     m_sendChannels = new NetSenderChannelBase[NetConstants.NumTotalChannels];
     m_receiveChannels = new NetReceiverChannelBase[NetConstants.NumTotalChannels];
     m_queuedAcks = new NetQueue<NetTuple<NetMessageType, int>>(4);
     m_statistics = new NetConnectionStatistics(this);
     m_averageRoundtripTime = -1.0f;
 }
开发者ID:andva,项目名称:Eulerian-ShootEmUp,代码行数:13,代码来源:NetConnection.cs


示例19: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            NetPeerConfiguration config = new NetPeerConfiguration("MMC");
            config.MaximumConnections = 100;
            config.Port = 3939;
            // Enable DiscoveryResponse messages
            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
            config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);

            s_server = new NetPeer(config);
            Output("listening on " + config.Port.ToString());
            s_server.Start();
        }
开发者ID:jluchiji,项目名称:MMC_Server,代码行数:13,代码来源:Form1.cs


示例20: GetNetOutgoingMessage

        /// <summary>
        /// Gets a <see cref="NetOutgoingMessage"/>.
        /// </summary>
        /// <param name="netPeer">The <see cref="NetPeer"/> instance that the message is to be used on.</param>
        /// <param name="size">The minimum initial size of the <see cref="NetOutgoingMessage"/> in bytes.</param>
        /// <returns>
        /// The <see cref="NetOutgoingMessage"/> instance to use.
        /// </returns>
        public static NetOutgoingMessage GetNetOutgoingMessage(NetPeer netPeer, int size)
        {
            // Round up to the next power-of-2 size (if not already there) to make allocations a bit more consistency-sized
            // and grabbing from the internal pool will hopefully be faster, even if it does mean over-allocating a bit more.
            // Also, never use less than 16 bytes since there is not much point in cluttering things up with tiny buffers.
            if (size < 16)
                size = 16;
            else
                size = BitOps.NextPowerOf2(size);

            // Grab the NetOutgoingMessage from the internal buffer
            return netPeer.CreateMessage(size);
        }
开发者ID:wtfcolt,项目名称:game,代码行数:21,代码来源:SocketHelper.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Network.NetPeerConfiguration类代码示例发布时间:2022-05-26
下一篇:
C# Network.NetOutgoingMessage类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap