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


C# NetClient.SendMessage方法代码示例

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


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

示例1: sendRequest

 public void sendRequest(NetClient n, int id, byte property)
 {
     NetOutgoingMessage propertyMessage = n.CreateMessage();
     propertyMessage.Write(id);
     NetOutgoingMessage idMessage = n.CreateMessage();
     idMessage.Write(property);
     n.SendMessage(idMessage, NetDeliveryMethod.ReliableOrdered);
     n.SendMessage(propertyMessage, NetDeliveryMethod.ReliableOrdered);
 }
开发者ID:vs-team,项目名称:internship-tilburg,代码行数:9,代码来源:CasanovaNetwork.cs

示例2: connectToServer

 public NetClient connectToServer(string ip, int port, string appname, int playernr, int entityID)
 {
     NetPeerConfiguration npc = new NetPeerConfiguration(appname);
     NetClient n = new NetClient(npc);
     n.Connect(ip, port);
     Debug.Log("Connected succesfully!");
     NetOutgoingMessage mess = n.CreateMessage();
     mess.Write(playernr);
     NetOutgoingMessage nm = n.CreateMessage();
     nm.Write(entityID);
     n.SendMessage(mess, NetDeliveryMethod.ReliableOrdered);
     n.SendMessage(nm, NetDeliveryMethod.ReliableOrdered);
     Debug.Log("Cleared identity with server!");
     return n;
 }
开发者ID:vs-team,项目名称:internship-tilburg,代码行数:15,代码来源:CasanovaNetwork.cs

示例3: SendUpdates

 public void SendUpdates(NetClient client)
 {
     NetOutgoingMessage om = client.CreateMessage();
     om.Write(Helpers.TransferType.ProjectileUpdate);
     om.Write(new ProjectileTransferableData(client.UniqueIdentifier,ID,IsValid,Position,Angle));
     client.SendMessage(om, NetDeliveryMethod.UnreliableSequenced);
 }
开发者ID:elefantstudio-se,项目名称:xna-lidgren-multiplayer-game,代码行数:7,代码来源:ProjectileLocal.cs

示例4: Main

        public static void Main(string[] args)
        {
            Console.WriteLine("[CLIENT] Testing Lidgren-Network-v3...");

            NetPeerConfiguration clientConfig = new NetPeerConfiguration("test");
            clientConfig.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
            NetClient client = new NetClient(clientConfig);
            client.Start();

            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));

            Console.WriteLine("IP to connect to: ");
            String ip = Console.ReadLine();

            client.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ip), 12345));

            while(true) {
                string msg = Console.ReadLine();

                NetOutgoingMessage sendMsg = client.CreateMessage();
                sendMsg.Write("[CLIENT] " + msg);
                client.SendMessage(sendMsg, NetDeliveryMethod.ReliableOrdered);
            }
        }
开发者ID:uwrov,项目名称:teaching,代码行数:25,代码来源:Client.cs

示例5: Main

		static void Main(string[] args)
		{
			var config = new NetPeerConfiguration("enctest");
			var client = new NetClient(config);
			client.Start();

			System.Threading.Thread.Sleep(100); // give server time to start up

			client.Connect("localhost", 14242);

			var encryption = new NetAESEncryption(client, "Hallonpalt");

			// loop forever
			while (true)
			{
				// read messages
				var inc = client.ReadMessage();
				if (inc != null)
				{
					switch (inc.MessageType)
					{
						case NetIncomingMessageType.DebugMessage:
						case NetIncomingMessageType.WarningMessage:
						case NetIncomingMessageType.VerboseDebugMessage:
						case NetIncomingMessageType.ErrorMessage:
							Console.WriteLine(inc.ReadString());
							break;
						case NetIncomingMessageType.StatusChanged:
							var status = (NetConnectionStatus)inc.ReadByte();
							Console.WriteLine(inc.SenderConnection + " (" + status + ") " + inc.ReadString());
							break;
					}
				}

				// if we're connected, get input and send
				if (client.ServerConnection != null && client.ServerConnection.Status == NetConnectionStatus.Connected)
				{
					Console.WriteLine("Type a message:");
					var input = Console.ReadLine();

					var msg = client.CreateMessage();
					msg.Write(input);
					encryption.Encrypt(msg);

					var ok = client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered);
					Console.WriteLine("Message sent: " + ok);
				}
			}
		}
开发者ID:g1111111g,项目名称:lidgren-network-gen3,代码行数:49,代码来源:Program.cs

示例6: Main

        static List<Player> players; //This will hold all players info from server

        #endregion Fields

        #region Methods

        static void Main(string[] args)
        {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            players = new List<Player>();
            Config = new NetPeerConfiguration("DND Server");//APP ID
            Console.WriteLine("Created Client Configuration.");
               // Config.Port = _SERVERPORT;
            Client = new NetClient(Config);
            Console.WriteLine("Initialized client socket");
            Client.RegisterReceivedCallback(new SendOrPostCallback(RecieveData));
            //Register the recieve callback.  Better if its before when the socket starts
            Client.Start();//start the socket
            Console.WriteLine("started the client socket");
            Client.Connect("localhost", _SERVERPORT);//connect the client to the server
            Console.WriteLine("Requesting Connection to server");
            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            //An example input manager to get respont on console
            new Thread(new ThreadStart(delegate
            {
                string input;

                while ((input = Console.ReadLine()) != null)
                {
                    Console.WriteLine("Console input.");
                    string[] prms = input.Split(' ');//params for the input

                    switch (prms[0])//The first param is the command name
                    {
                        case "/changename":
                            //TODO: add code later
                            break;
                        case "/say":
                            NetOutgoingMessage outmsg;
                            outmsg = Client.CreateMessage();
                            outmsg.Write((byte)Headers.Chat);
                            string Message = "";
                            for(int i = 1; i < prms.Length; i++)
                                Message += prms[i] + " ";
                            Message += "\n";
                            outmsg.Write(Message);
                            Client.SendMessage(outmsg, NetDeliveryMethod.ReliableOrdered);
                                break;
                    }

                }
            })).Start();
            //END INPUT MANAGEMENT
        }
开发者ID:TimBritton,项目名称:Server,代码行数:54,代码来源:Client.cs

示例7: setupNetworking

        private void setupNetworking()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("SkySlider");
            config.EnableMessageType(NetIncomingMessageType.Data);
            client = new NetClient(config);
            client.Start();
            client.Connect("156.143.93.190", 16645);

            NetOutgoingMessage newClientMsg = client.CreateMessage();
            newClientMsg.Write((byte)ClientToServerProtocol.NewConnection);
            newClientMsg.Write(localPlayerName);
            Thread.Sleep(500);

            client.SendMessage(newClientMsg, NetDeliveryMethod.ReliableOrdered);

            Thread thread = new Thread(new ThreadStart(listenForPackets));
            thread.Start();
        }
开发者ID:bschwind,项目名称:Sky-Slider,代码行数:18,代码来源:MainGamePanel.cs

示例8: Send

        /// <summary>
        ///     Sends this instance of a packet to the server.
        /// </summary>
        /// <param name="client">
        ///     The server to send the packet to.
        /// </param>
        public override void Send(NetClient client)
        {
            // Create a new message
            var msg = client.CreateMessage();

            // Write header
            msg.Write(this.Header);

            // Write target
            msg.Write(this.targetNetworkId);

            // Write plugin data
            msg.Write(this.Message.Data);

            // Manually encrypt message
            msg.Encrypt(Live.EncryptionAlgorithm);

            // Send Packet
            client.SendMessage(msg, NetDeliveryMethod.Unreliable);
        }
开发者ID:Trontastic,项目名称:LeagueSharp.Live,代码行数:26,代码来源:PluginDataPacket.cs

示例9: Finalize

        /// <summary>
        ///     Encrypts the packet and sends it to the server.
        /// </summary>
        /// <param name="client">
        ///     The client.
        /// </param>
        /// <param name="message">
        ///     The message.
        /// </param>
        public void Finalize(NetClient client, NetOutgoingMessage message)
        {
            if (!this.FinalizePacket)
            {
                return;
            }

            this.Message.Encrypt(Live.EncryptionAlgorithm);
            client.SendMessage(message, NetDeliveryMethod.Unreliable);
        }
开发者ID:Trontastic,项目名称:LeagueSharp.Live,代码行数:19,代码来源:Packet.cs

示例10: Send

 /// <summary>
 ///     Sends this instance of a packet to the server. (Be sure to write the header first!)
 /// </summary>
 /// <param name="client">
 ///     The client.
 /// </param>
 public virtual void Send(NetClient client)
 {
     client.SendMessage(this.Message, NetDeliveryMethod.Unreliable);
 }
开发者ID:Trontastic,项目名称:LeagueSharp.Live,代码行数:10,代码来源:Packet.cs

示例11: SendUpdates

 public void SendUpdates(NetClient client)
 {
     var message = client.CreateMessage();
     message.Write(Helpers.TransferType.HealthUpdate);
     message.Write(new HealthTransferableData(client.UniqueIdentifier, ID, IsValid, index, Value));
     client.SendMessage(message, NetDeliveryMethod.ReliableOrdered);
 }
开发者ID:elefantstudio-se,项目名称:xna-lidgren-multiplayer-game,代码行数:7,代码来源:HealthBar.cs

示例12: Main

        static void Main(string[] args)
        {
            NetConfiguration config = new NetConfiguration("durable");
            NetClient client = new NetClient(config);

            client.SimulatedMinimumLatency = 0.05f;
            client.SimulatedLatencyVariance = 0.025f;
            client.SimulatedLoss = 0.03f;

            // wait half a second to allow server to start up in Visual Studio
            Thread.Sleep(500);

            // create a buffer to read data into
            NetBuffer buffer = client.CreateBuffer();

            // connect to localhost
            client.Connect("localhost", 14242, Encoding.ASCII.GetBytes("Hail from client"));

            // enable some library messages
            client.SetMessageTypeEnabled(NetMessageType.BadMessageReceived, true);
            //client.SetMessageTypeEnabled(NetMessageType.VerboseDebugMessage, true);
            client.SetMessageTypeEnabled(NetMessageType.ConnectionRejected, true);

            FileStream fs = new FileStream("./clientlog.txt", FileMode.Create, FileAccess.Write, FileShare.Read);
            StreamWriter wrt = new StreamWriter(fs);
            Output(wrt, "Log started at " + DateTime.Now);
            wrt.Flush();

            // create a stopwatch
            Stopwatch sw = new Stopwatch();
            sw.Start();
            int loops = 0;

            while (!Console.KeyAvailable)
            {
                NetMessageType type;
                if (client.ReadMessage(buffer, out type))
                {
                    switch (type)
                    {
                        case NetMessageType.StatusChanged:
                            if (client.ServerConnection.RemoteHailData != null)
                                Output(wrt, "New status: " + client.Status + " (" + buffer.ReadString() + ") Remote hail is: " + Encoding.ASCII.GetString(client.ServerConnection.RemoteHailData));
                            else
                                Output(wrt, "New status: " + client.Status + " (" + buffer.ReadString() + ") Remote hail hasn't arrived.");
                            break;
                        case NetMessageType.BadMessageReceived:
                        case NetMessageType.ConnectionRejected:
                        case NetMessageType.DebugMessage:
                        case NetMessageType.VerboseDebugMessage:
                            //
                            // These types of messages all contain a string in the buffer; display it.
                            //
                            Output(wrt, buffer.ReadString());
                            break;
                        case NetMessageType.Data:
                        default:
                            //
                            // For this application; server doesn't send any data... so Data messages are unhandled
                            //
                            Output(wrt, "Unhandled: " + type + " " + buffer.ToString());
                            break;
                    }
                }

                // send a message every second
                if (client.Status == NetConnectionStatus.Connected && sw.Elapsed.TotalMilliseconds >= 516)
                {
                    loops++;
                    //Console.WriteLine("Sending message #" + loops);
                    Console.Title = "Client; Messages sent: " + loops;

                    Output(wrt, "Sending #" + loops + " at " + NetTime.ToMillis(NetTime.Now));
                    NetBuffer send = client.CreateBuffer();
                    send.Write("Message #" + loops);
                    client.SendMessage(send, NetChannel.ReliableInOrder14);

                    sw.Reset();
                    sw.Start();
                }

                Thread.Sleep(1);
            }

            // clean shutdown
            client.Shutdown("Application exiting");
            wrt.Close();
        }
开发者ID:JeffM2501,项目名称:HackSharp,代码行数:88,代码来源:Program.cs

示例13: SendUpdates

 public void SendUpdates(NetClient client)
 {
     NetOutgoingMessage om = client.CreateMessage();
     om.Write(Helpers.TransferType.PlayerUpdate);
     om.Write(new PlayerTransferableData(SessionID, ID, Index, Position, Angle, IsValid));
     client.SendMessage(om, NetDeliveryMethod.Unreliable);
 }
开发者ID:elefantstudio-se,项目名称:xna-lidgren-multiplayer-game,代码行数:7,代码来源:LocalPlayer.cs

示例14: Main


//.........这里部分代码省略.........

			client.Connect("127.0.0.1", 14242);

			List<string> events = new List<string>();

			double end = double.MaxValue;
			double disconnect = double.MaxValue;

			while (NetTime.Now < end)
			{
				double now = NetTime.Now;

				NetMessageType nmt;
				NetConnection sender;

				//
				// client
				//
				if (client.ReadMessage(clientBuffer, out nmt))
				{
					switch (nmt)
					{
						case NetMessageType.StatusChanged:
							Console.WriteLine("Client: " + client.Status + " (" + clientBuffer.ReadString() + ")");
							events.Add("CStatus " + client.Status);
							if (client.Status == NetConnectionStatus.Connected)
							{
								// send reliable message
								NetBuffer buf = client.CreateBuffer();
								buf.Write(true);
								buf.Write((int)52, 7);
								buf.Write("Hallon");

								client.SendMessage(buf, NetChannel.ReliableInOrder1, new NetBuffer("kokos"));
							}

							if (client.Status == NetConnectionStatus.Disconnected)
								end = NetTime.Now + 1.0; // end in one second

							break;
						case NetMessageType.Receipt:
							events.Add("CReceipt " + clientBuffer.ReadString());
							break;
						case NetMessageType.ConnectionRejected:
						case NetMessageType.BadMessageReceived:
							throw new Exception("Failed: " + nmt);
						case NetMessageType.DebugMessage:
							// silently ignore
							break;
						default:
							// ignore
							Console.WriteLine("Ignored: " + nmt);
							break;
					}
				}

				//
				// server
				//
				if (server.ReadMessage(serverBuffer, out nmt, out sender))
				{
					switch (nmt)
					{
						case NetMessageType.StatusChanged:
							events.Add("SStatus " + sender.Status);
							Console.WriteLine("Server: " + sender.Status + " (" + serverBuffer.ReadString() + ")");
开发者ID:marvel54,项目名称:lidgren-network,代码行数:67,代码来源:Program.cs

示例15: Main

		static void Main(string[] args)
		{
			// create a client with a default configuration
			NetConfiguration config = new NetConfiguration("chatApp");
			NetClient client = new NetClient(config);
			client.SetMessageTypeEnabled(NetMessageType.ConnectionRejected, true);
			client.SetMessageTypeEnabled(NetMessageType.DebugMessage, true);
			//client.SetMessageTypeEnabled(NetMessageType.VerboseDebugMessage, true);
			client.Start();

			// Wait half a second to allow server to start up if run via Visual Studio
			Thread.Sleep(500);

			// Emit discovery signal
			client.DiscoverLocalServers(14242);

			// create a buffer to read data into
			NetBuffer buffer = client.CreateBuffer();

			// current input string
			string input = "";

			// keep running until the user presses a key
			Console.WriteLine("Type 'quit' to exit client");
			Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
			s_keepGoing = true;
			while (s_keepGoing)
			{
				NetMessageType type;

				// check if any messages has been received
				while (client.ReadMessage(buffer, out type))
				{
					switch (type)
					{
						case NetMessageType.ServerDiscovered:
							// just connect to any server found!

							// make hail
							NetBuffer buf = client.CreateBuffer();
							buf.Write("Hail from " + Environment.MachineName);
							client.Connect(buffer.ReadIPEndPoint(), buf.ToArray());
							break;
						case NetMessageType.ConnectionRejected:
							Console.WriteLine("Rejected: " + buffer.ReadString());
							break;
						case NetMessageType.DebugMessage:
						case NetMessageType.VerboseDebugMessage:
							Console.WriteLine(buffer.ReadString());
							break;
						case NetMessageType.StatusChanged:
							string statusMessage = buffer.ReadString();
							NetConnectionStatus newStatus = (NetConnectionStatus)buffer.ReadByte();
							Console.WriteLine("New status: " + newStatus + " (" + statusMessage + ")");
							break;
						case NetMessageType.Data:
							// The server sent this data!
							string msg = buffer.ReadString();
							Console.WriteLine(msg);
							break;
					}
				}

				while (Console.KeyAvailable)
				{
					ConsoleKeyInfo ki = Console.ReadKey();
					if (ki.Key == ConsoleKey.Enter)
					{
						if (!string.IsNullOrEmpty(input))
						{
							if (input == "quit")
							{
								// exit application
								s_keepGoing = false;
							}
							else
							{
								// Send chat message
								NetBuffer sendBuffer = new NetBuffer();
								sendBuffer.Write(input);
								client.SendMessage(sendBuffer, NetChannel.ReliableInOrder1);
								input = "";
							}
						}
					}
					else
					{
						input += ki.KeyChar;
					}
				}

				Thread.Sleep(1);
			}

			client.Shutdown("Application exiting");
		}
开发者ID:marvel54,项目名称:lidgren-network,代码行数:96,代码来源:Program.cs


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