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

C# Network.NetConnection类代码示例

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

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



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

示例1: RecvMCL

 public static void RecvMCL()
 {
     while(true) {
         Thread.Sleep(10);
         NetIncomingMessage msg;
         while((msg = peer.ReadMessage()) != null) {
             switch(msg.MessageType) {
                 case NetIncomingMessageType.VerboseDebugMessage:
                 case NetIncomingMessageType.DebugMessage:
                 case NetIncomingMessageType.WarningMessage:
                 case NetIncomingMessageType.ErrorMessage:
                     Console.WriteLine(msg.ReadString());
                     break;
                 case NetIncomingMessageType.StatusChanged:
                     Console.WriteLine(((NetConnectionStatus)msg.ReadByte()).ToString());
                     break;
                 case NetIncomingMessageType.DiscoveryResponse:
                     Console.WriteLine("Found server at " + msg.SenderEndPoint + " name: " + msg.ReadString());
                     peerConnect = peer.Connect(msg.SenderEndPoint);
                     break;
                 case NetIncomingMessageType.Data:
                     Console.WriteLine(msg.LengthBytes);
                     break;
                 default:
                     Console.WriteLine("Unhandled type: " + msg.MessageType);
                     break;
             }
         }
     }
 }
开发者ID:RegrowthStudios,项目名称:VoxelRTS,代码行数:30,代码来源:Program.cs


示例2: Modify

 public void Modify(NetConnection conn, uint id)
 {
     if(ConnectionDictionary.ContainsKey(conn))
     {
         ConnectionDictionary[conn] = id;
     }
 }
开发者ID:xxy1991,项目名称:cozy,代码行数:7,代码来源:ConnectionManager.cs


示例3: getClient

 public static KSPClient getClient(NetConnection clientConnection)
 {
     KSPClient returnVal;
     connectionToClient.TryGetValue(clientConnection, out returnVal);
     // FUCK IT THIS SHOULDNT EVER BE NULL ANYWAY
     return returnVal;
 }
开发者ID:TomCaserta,项目名称:KSPMulti,代码行数:7,代码来源:Client.cs


示例4: 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


示例5: SendMessage

        /// <summary>
        /// Send a message to a specific connection
        /// </summary>
        /// <param name="msg">The message to send</param>
        /// <param name="recipient">The recipient connection</param>
        /// <param name="method">How to deliver the message</param>
        /// <param name="sequenceChannel">Sequence channel within the delivery method</param>
        public NetSendResult SendMessage(NetOutgoingMessage msg, NetConnection recipient, NetDeliveryMethod method, int sequenceChannel)
        {
            if (msg == null)
                throw new ArgumentNullException("msg");
            if (recipient == null)
                throw new ArgumentNullException("recipient");
            if (sequenceChannel >= NetConstants.NetChannelsPerDeliveryMethod)
                throw new ArgumentOutOfRangeException("sequenceChannel");

            NetException.Assert(
                ((method != NetDeliveryMethod.Unreliable && method != NetDeliveryMethod.ReliableUnordered) ||
                ((method == NetDeliveryMethod.Unreliable || method == NetDeliveryMethod.ReliableUnordered) && sequenceChannel == 0)),
                "Delivery method " + method + " cannot use sequence channels other than 0!"
            );

            NetException.Assert(method != NetDeliveryMethod.Unknown, "Bad delivery method!");

            if (msg.m_isSent)
                throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently");
            msg.m_isSent = true;

            int len = NetConstants.UnfragmentedMessageHeaderSize + msg.LengthBytes; // headers + length, faster than calling msg.GetEncodedSize
            if (len <= recipient.m_currentMTU)
            {
                Interlocked.Increment(ref msg.m_recyclingCount);
                return recipient.EnqueueMessage(msg, method, sequenceChannel);
            }
            else
            {
                // message must be fragmented!
                SendFragmentedMessage(msg, new NetConnection[] { recipient }, method, sequenceChannel);
                return NetSendResult.Queued; // could be different for each connection; Queued is "most true"
            }
        }
开发者ID:ncoder,项目名称:MonoGame,代码行数:41,代码来源:NetPeer.Send.cs


示例6: 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


示例7: Character

 public Character(string name, int x, int y, NetConnection conn)
 {
     Name = name;
     X = x;
     Y = y;
     Connection = conn;
 }
开发者ID:juniogro10,项目名称:ThunderCat,代码行数:7,代码来源:Program.cs


示例8: 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


示例9: HandleNetworkMessage

 public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection client)
 {
     if (message.ComponentFamily == ComponentFamily.Equipment)
     {
         var type = (ComponentMessageType) message.MessageParameters[0];
         var replies = new List<ComponentReplyMessage>();
         switch (type) //Why does this send messages to itself THIS IS DUMB AND WILL BREAK THINGS. BZZZ
         {
             case ComponentMessageType.EquipItem:
                 EquipEntity(Owner.EntityManager.GetEntity((int) message.MessageParameters[1]));
                 break;
             case ComponentMessageType.EquipItemInHand:
                 EquipEntityInHand();
                 break;
             case ComponentMessageType.EquipItemToPart:
                 EquipEntityToPart((EquipmentSlot) message.MessageParameters[1],
                                   Owner.EntityManager.GetEntity((int) message.MessageParameters[2]));
                 break;
             case ComponentMessageType.UnEquipItemToFloor:
                 UnEquipEntity(Owner.EntityManager.GetEntity((int) message.MessageParameters[1]));
                 break;
             case ComponentMessageType.UnEquipItemToHand:
                 if (!Owner.HasComponent(ComponentFamily.Hands))
                     return; //TODO REAL ERROR MESSAGE OR SOME FUCK SHIT
                 UnEquipEntityToHand(Owner.EntityManager.GetEntity((int) message.MessageParameters[1]));
                 break;
             case ComponentMessageType.UnEquipItemToSpecifiedHand:
                 if (!Owner.HasComponent(ComponentFamily.Hands))
                     return; //TODO REAL ERROR MESSAGE OR SOME FUCK SHIT
                 UnEquipEntityToHand(Owner.EntityManager.GetEntity((int) message.MessageParameters[1]),
                                     (Hand) message.MessageParameters[2]);
                 break;
         }
     }
 }
开发者ID:Gartley,项目名称:ss13remake,代码行数:35,代码来源:EquipmentComponent.cs


示例10: OnDisconnected

        internal override void OnDisconnected(NetConnection conn)
        {
            //vij dali e igral
            if (!clients.Contains(conn))
                return;

        }
开发者ID:toshinto,项目名称:2dBattleground,代码行数:7,代码来源:Server.cs


示例11: PlayerClient

 public PlayerClient(NetConnection Connection)
     : base()
 {
     Location = new Vector2((375 * 40) + 1, (375 * 40) + 1);
         ClientConnection = Connection;
         Sex = LastSex;
 }
开发者ID:fusspawn,项目名称:sobriety,代码行数:7,代码来源:PlayerClient.cs


示例12: SetClientCameraFollow

 private static void SetClientCameraFollow(long ID, NetConnection Connection)
 {
     NetOutgoingMessage Message = NetworkManager.Server.CreateMessage();
     Message.Write((byte)MessageTypes.CameraFocusAt);
     Message.Write(ID);
     NetworkManager.Server.SendMessage(Message, Connection, NetDeliveryMethod.ReliableUnordered);
 }
开发者ID:fusspawn,项目名称:sobriety,代码行数:7,代码来源:CharacterManager.cs


示例13: SendMessage

 private static void SendMessage(NetServer server, MsgBase msg, NetConnection conn)
 {
     NetOutgoingMessage om = server.CreateMessage();
     om.Write(msg.Id);
     msg.W(om);
     server.SendMessage(om, conn, NetDeliveryMethod.Unreliable, 0);
 }
开发者ID:xxy1991,项目名称:cozy,代码行数:7,代码来源:ServerOperat.cs


示例14: Connection

 /// <summary>
 /// Creates a new connection instance.
 /// </summary>
 /// <param name="messagingSettings">Qbes messaging configuration
 /// node</param>
 /// <param name="connection">NetConnection object</param>
 /// <param name="callback">Callback for completed received multipart
 /// messages</param>
 public Connection(MessagingConfiguration messagingSettings, NetConnection connection, CompletedReceivedMultipartMessage callback)
 {
     _MaxMessageSize = messagingSettings.MaxMessageSize;
      _Connection = connection;
      _RemoteEndPoint = connection.RemoteEndPoint;
      _CompletedReceivedMultipartCallback = callback;
 }
开发者ID:daxola123,项目名称:Qbes,代码行数:15,代码来源:Connection.cs


示例15: AddConnection

        public void AddConnection(NetConnection connection)
        {
            var lobbyPlayer = new LobbyPlayer();
            lobbyPlayer.Id = idToGive;
            connection.Tag = lobbyPlayer;
            clients.Add(connection);
            idToGive++;

            var memory = new MemoryStream();
            var writer = new BinaryWriter(memory);
            writer.Write((byte) LobbyProtocol.SetID);
            writer.Write(lobbyPlayer.Id);
            myServer.SendLobbyData(memory.ToArray(), connection);

            memory = new MemoryStream();
            writer = new BinaryWriter(memory);
            writer.Write((byte)LobbyProtocol.SendAllPlayers);
            writer.Write(AllPlayersData());
            myServer.SendLobbyData(memory.ToArray());

            SendData(new byte[1]{MaxSlots}, LobbyProtocol.SendMaxSlots );

            memory = new MemoryStream();
            writer = new BinaryWriter(memory);
            writer.Write(Name);
            writer.Write(Description);
            SendData(memory.ToArray(), LobbyProtocol.SendLobbyName);
        }
开发者ID:Austech,项目名称:HGlueSim,代码行数:28,代码来源:Lobby.cs


示例16: fireClientApproval

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


示例17: NetReliableOrderedReceiver

		public NetReliableOrderedReceiver(NetConnection connection, int windowSize)
			: base(connection)
		{
			m_windowSize = windowSize;
			m_withheldMessages = new NetIncomingMessage[windowSize];
			m_earlyReceived = new NetBitVector(windowSize);
		}
开发者ID:Cardanis,项目名称:MonoGame,代码行数:7,代码来源:NetReliableOrderedReceiver.cs


示例18: fireDataRecieved

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


示例19: SendCheckpoint

        void SendCheckpoint(NetConnection sendTo)
        {
            Log("SendCheckpoint");
            var checkpointEvent = new MyEventCheckpoint();
            checkpointEvent.Checkpoint = GetCheckpoint();

            Peers.NetworkClient.Send(ref checkpointEvent, sendTo, NetDeliveryMethod.ReliableOrdered, 0, 1024 * 1024);

            // Send missiles, cannon shots etc.
            m_entitiesToTransfer.Clear();
            MyEntities.FindEntities(AmmoEntitiesPredicate, m_entitiesToTransfer);
            foreach (var e in m_entitiesToTransfer)
            {
                var ammo = (MyAmmoBase)e;

                var weapon = MyGuiSmallShipHelpers.GetFirstWeaponType(ammo.AmmoType);
                if (!weapon.HasValue) continue;

                MyEventShoot shootMsg = new MyEventShoot();
                shootMsg.Ammo = ammo.AmmoType;
                shootMsg.Position = new MyMwcPositionAndOrientation(ammo.WorldMatrix);
                shootMsg.ProjectileEntityId = MyEntityIdentifier.ToNullableInt(ammo.EntityId);
                shootMsg.ShooterEntityId = (ammo.OwnerEntity != null && ammo.OwnerEntity.EntityId.HasValue) ? ammo.OwnerEntity.EntityId.Value.NumericValue : 0;
                shootMsg.TargetEntityId = null;
                shootMsg.Weapon = weapon.Value;
                Peers.NetworkClient.Send(ref shootMsg, sendTo, NetDeliveryMethod.ReliableOrdered, 0);
            }
        }
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:28,代码来源:MyMultiplayerGameplay.Join.cs


示例20: fireStatusChanged

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Network.NetIncomingMessage类代码示例发布时间:2022-05-26
下一篇:
C# Network.NetClient类代码示例发布时间: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