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


C# NetClient.RegisterReceivedCallback方法代码示例

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


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

示例1: Init

        public void Init(string app_identifier, bool auth_flush_send_queue, bool use_multi_thread)
        {
            this.app_identifier = app_identifier;

            NetPeerConfiguration config = new NetPeerConfiguration(this.app_identifier);
            config.AutoFlushSendQueue = auth_flush_send_queue;

            net_client = new NetClient(config);

            if (SynchronizationContext.Current == null)
            {
                SynchronizationContext.SetSynchronizationContext(new STASynchronizationContext());
            }

            if (use_multi_thread == false && SynchronizationContext.Current != null)
            {
                net_client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
            }
            else
            {
                net_worker = new BackgroundWorker();
                net_worker.DoWork += new DoWorkEventHandler(net_worker_DoWork);
                net_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(net_worker_RunWorkerCompleted);
            }
        }
开发者ID:jeidee,项目名称:Lidgren.Network.Wrapper,代码行数:25,代码来源:MessageClient.cs

示例2: Client

 public Client()
 {
     NetPeerConfiguration config = new NetPeerConfiguration("CozyAnywhere");
     config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
     client                      = new NetClient(config);
     client.RegisterReceivedCallback(RecivePacket);
 }
开发者ID:shangshen,项目名称:cozy,代码行数:7,代码来源:ClientMain.cs

示例3: ConnectServer

 private static NetClient ConnectServer()
 {
     var config = new NetPeerConfiguration("pic") {EnableUPnP = true};
     var thisClient = new NetClient(config);
     thisClient.RegisterReceivedCallback(HandleMessage);
     return thisClient;
 }
开发者ID:JamieH,项目名称:Pictionary,代码行数:7,代码来源:Network.cs

示例4: Connect

        public static void Connect(IPEndPoint endpoint, MMDevice device, ICodec codec)
        {
            var config = new NetPeerConfiguration("airgap");

            _client = new NetClient(config);
            _client.RegisterReceivedCallback(MessageReceived);

            _client.Start();

            _waveIn = new WasapiLoopbackCapture(device);
            _codec = codec;

            _sourceFormat = _waveIn.WaveFormat;
            _targetFormat = new WaveFormat(_codec.SampleRate, _codec.Channels); // format to convert to

            _waveIn.DataAvailable += SendData;
            _waveIn.RecordingStopped += (sender, args) => Console.WriteLine("Stopped");
            // TODO: RecordingStopped is called when you change the audio device settings, should recover from that

            NetOutgoingMessage formatMsg = _client.CreateMessage();
            formatMsg.Write(_targetFormat.Channels);
            formatMsg.Write(_targetFormat.SampleRate);
            formatMsg.Write(codec.Name);

            _client.Connect(endpoint, formatMsg);
        }
开发者ID:JamieH,项目名称:AudioGap,代码行数:26,代码来源:Network.cs

示例5: CozyClient

 public CozyClient(string ClientName)
 {
     NetPeerConfiguration config = new NetPeerConfiguration(ClientName);
     config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
     InnerClient = new NetClient(config);
     InnerClient.RegisterReceivedCallback(RecivePacket);
 }
开发者ID:xxy1991,项目名称:cozy,代码行数:7,代码来源:CozyClient.Main.cs

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

示例7: button1_Click

 private void button1_Click(object sender, EventArgs e)
 {
     var config = new NetPeerConfiguration("Chat_lobby");
     client = new NetClient(config);
     client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
     client.Start();
     client.Connect("localhost", 12345);
 }
开发者ID:SharpEdgeEntertainment,项目名称:FrozenFlameFramework,代码行数:8,代码来源:Form1.cs

示例8: Init

        public override void Init()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("chat");
            config.AutoFlushSendQueue = false;
            s_client = new NetClient(config);

            s_client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
        }
开发者ID:ajmd17,项目名称:apexengine-sharp,代码行数:8,代码来源:ClientGameComponent.cs

示例9: Client

 public Client()
 {
     NetPeerConfiguration config = new NetPeerConfiguration("ths");
     config.AutoFlushSendQueue = false;
     _client = new NetClient(config);
     _client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
     InitializeInteractionActionsTable();
     InitializeOutboxActionTable();
     NetworkStatus = NetworkStatusEnum.Disconnected;
 }
开发者ID:galaxyyao,项目名称:TouhouGrave,代码行数:10,代码来源:Client.cs

示例10: start

        public static void start()
        {
            net = new NetClient(config);

            net.RegisterReceivedCallback(new SendOrPostCallback((e) =>
            {
                message = net.ReadMessage();
                messageRecieved(message);
            }), new SynchronizationContext());

            print("info", "Starting...");
            net.Start();
            print("info", "Client Running");
        }
开发者ID:law4x,项目名称:stonevox3d,代码行数:14,代码来源:Client.cs

示例11: ConnectPlayerToLobby

        public static void ConnectPlayerToLobby(string playername, Color playercolor)
        {
            NetPeerConfiguration config = new NetPeerConfiguration("chat");
            config.AutoFlushSendQueue = false;
            s_client = new NetClient(config);

            s_client.RegisterReceivedCallback(new SendOrPostCallback(LobbyForm.GotMessage));

            string hailmessage = guid.ToString() + ";" + playername + ";" + Convert.ToString(playercolor.ToArgb());

            s_client.Start();
            NetOutgoingMessage hail = s_client.CreateMessage(hailmessage);
            s_client.Connect(settings.ServerAdresse, settings.ChatPort, hail);
        }
开发者ID:JueZ,项目名称:ITP,代码行数:14,代码来源:Program.cs

示例12: ConnectToServer

        public static void ConnectToServer()
        {
            NetPeerConfiguration netconfig = new NetPeerConfiguration("game");

            netclient = new NetClient(netconfig);

            if (SynchronizationContext.Current == null)
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

            netclient.RegisterReceivedCallback(new SendOrPostCallback(ReceivedData));
            netclient.Start();

            NetOutgoingMessage message = netclient.CreateMessage("Connect");
            netclient.Connect(settings.ServerAdresse, settings.GamePort, message);
        }
开发者ID:JueZ,项目名称:ITP,代码行数:15,代码来源:Program.cs

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

示例14: ClientConnection

        internal ClientConnection(bool dummy)
        {
            if (!dummy)
             {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

            NetPeerConfiguration peerConfig = new NetPeerConfiguration("Qbes");
            peerConfig.AutoFlushSendQueue = true;
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.DebugMessage, true);
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ErrorMessage, true);
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.VerboseDebugMessage, true);
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.WarningMessage, true);
            _Client = new NetClient(peerConfig);
            _Client.RegisterReceivedCallback(new SendOrPostCallback(ReceivedMessage));
             }
        }
开发者ID:daxola123,项目名称:Qbes,代码行数:16,代码来源:ClientConnection.cs

示例15: Main

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

			NetPeerConfiguration config = new NetPeerConfiguration("chat");
			config.AutoFlushSendQueue = false;
			s_client = new NetClient(config);

			s_client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage)); 

			Application.Run(s_form);

			s_client.Shutdown("Bye");
		}
开发者ID:pr0gramm3r1,项目名称:AngryTanks,代码行数:16,代码来源:Program.cs


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