當前位置: 首頁>>代碼示例>>C#>>正文


C# Socket.On方法代碼示例

本文整理匯總了C#中Quobject.SocketIoClientDotNet.Client.Socket.On方法的典型用法代碼示例。如果您正苦於以下問題:C# Socket.On方法的具體用法?C# Socket.On怎麽用?C# Socket.On使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Quobject.SocketIoClientDotNet.Client.Socket的用法示例。


在下文中一共展示了Socket.On方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: OgsMessageTest

        public void OgsMessageTest()
        {
            var log = LogManager.GetLogger(Global.CallerName());
            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            var events = new Queue<object>();

            var options = CreateOptions();
            var uri = CreateUri();
            socket = IO.Socket(uri, options);
            socket.On(Socket.EVENT_CONNECT, () =>
            {
                log.Info("EVENT_CONNECT");
                socket.Emit("parser_error#21");
            });

            socket.On("parser_error#21_response",
                (data) =>
                {
                    log.Info("EVENT_MESSAGE");
                    events.Enqueue(data);
                    ManualResetEvent.Set();
                });

            //socket.Open();
            ManualResetEvent.WaitOne();
            socket.Close();
            var obj = events.Dequeue();
            Assert.Equal("{\"handicap\":0,\"disable_analysis\":false,\"private\":false,\"height\":19,\"time_control\":{\"time_control\":\"byoyomi\",\"period_time\":45,\"main_time\":1800,\"periods\":5},\"ranked\":false,\"meta_groups\":[132,3,196,261,327,489,43,418,302,463,242,403,425,24,25,154,28,157],\"komi\":6.5,\"game_id\":1333070,\"width\":19,\"rules\":\"japanese\",\"black_player_id\":71283,\"white_player_id\":78080,\"players\":{\"white\":{\"username\":\"Rvzy\",\"egf\":501.413,\"rank\":14,\"id\":78080,\"accepted_stones\":\"mcidkdldmdiekeefgfifkfdgegfghgkgfhghhhihkhnhfigihikinifjhjjjkjnjdkekfkgkhkjknkflhljlgmhmimjmgnknlnmnnngo\",\"accepted_strict_seki_mode\":false},\"black\":{\"username\":\"心の光\",\"egf\":353.454,\"rank\":12,\"id\":71283,\"accepted_stones\":\"mcidkdldmdiekeefgfifkfdgegfghgkgfhghhhihkhnhfigihikinifjhjjjkjnjdkekfkgkhkjknkflhljlgmhmimjmgnknlnmnnngo\",\"accepted_strict_seki_mode\":false}},\"game_name\":\"Friendly Match\",\"phase\":\"finished\",\"history\":[],\"initial_player\":\"black\",\"moves\":\"pddpppddfqfocqdjcpcodqepeqncqfkcfcgdcccddcfdecgcgbhbfahcbdbebccfpjnpqnjphphoioipgohngngphqfpgmilcndnbocmdoengqeocodlgkijhiiihhjgifighghfhkikekejfjelflfihjgihminimjnjmkmjlkljkkkjjliihjikjljkijhkhlgkgjfiejegfheidickfmekejdhllhfgehegdhfhedghffeffedgcgdkckfkcibmclblbkldlcmdndmcmbkdjcaeafadnfknjolnlplkllmkmmmnnmnnnkmjnjminimhnhmglfnlomolonmloonglmiqjqjrkrirmfofpbqcorproqpqopplpmqmpoqoosqppsqrqsrrrsoeneodwO6obqblaocnbpaoaqaksjsakalhafbsssr....\",\"allow_self_capture\":false,\"automatic_stone_removal\":false,\"free_handicap_placement\":false,\"allow_ko\":false,\"allow_superko\":true,\"superko_algorithm\":\"ssk\",\"score_territory\":true,\"score_territory_in_seki\":false,\"score_stones\":false,\"score_prisoners\":true,\"score_passes\":true,\"white_must_pass_last\":false,\"opponent_plays_first_after_resume\":true,\"strict_seki_mode\":false,\"initial_state\":{\"black\":\"\",\"white\":\"\"},\"start_time\":1420522348,\"clock\":{\"game_id\":1333070,\"current_player\":78080,\"black_player_id\":71283,\"white_player_id\":78080,\"title\":\"Friendly Match\",\"last_move\":1420524830517,\"expiration\":1420525270589,\"black_time\":{\"thinking_time\":909.8829999999991,\"periods\":5,\"period_time\":45},\"white_time\":{\"thinking_time\":215.07199999999966,\"periods\":5,\"period_time\":45},\"pause_delta\":-517,\"expiration_delta\":440072,\"now\":1420524830517,\"paused_since\":1420524830},\"pause_control\":{\"stone-removal\":true},\"paused_since\":1420524830,\"removed\":\"mcidkdldmdiekeefgfifkfdgegfghgkgfhghhhihkhnhfigihikinifjhjjjkjnjdkekfkgkhkjknkflhljlgmhmimjmgnknlnmnnngo\",\"auto_scoring_done\":true,\"score\":{\"white\":{\"total\":154.5,\"stones\":0,\"territory\":101,\"prisoners\":47,\"scoring_positions\":\"iajakaibjbkblbmanamckdldmdcedeeegekeledfefgfkfdgegfggghgkgfhghhhihkhdieifigihikifjgjhjjjkjdkekfkgkhkjkflglhljldmemfmgmhmimjmfngngohdidieifbfagbgahbhchaibiajbjcjknlnmnnnkolomonokpmpkqlqmqnqlrmrnrlsmsnsio\",\"handicap\":0,\"komi\":6.5},\"black\":{\"total\":101,\"stones\":0,\"territory\":94,\"prisoners\":7,\"scoring_positions\":\"aabacadaeaabbbcbdbebacrasarbsbrcscqdrdsdpeqeresepfrfsfogpgqgrgsgnhohphqhrhshnioipiqirisinjojqjrjsjnkokpkqkrkskqlrlslrmsmrnsnrosorpspqqrqsqamanbnaoapbpaqbqarbrcrdrerfrgrhrasbscsdsesfsgshsis\",\"handicap\":0,\"komi\":0}},\"winner\":78080,\"outcome\":\"53.5 points\",\"end_time\":1420524844}", obj);
        }
開發者ID:rong77,項目名稱:SocketIoClientDotNet,代碼行數:30,代碼來源:ServerConnectionTest.cs

示例2: WebNfcListener

        public WebNfcListener(string ident)
        {
            if (!ident.Contains("@"))
                throw new ArgumentException("Invalid ident - missing @");
            var parts = ident.Split('@');
            if(parts.Length != 2)
                throw new ArgumentException("Invalid ident - invalid length");
            _endpoint = parts[0];
            _address = parts[1];

            _ioHandler = IO.Socket(_address);

            _ioHandler.On(Socket.EVENT_CONNECT, (obj) =>
            {
                OnConnected?.Invoke();
            });

            _ioHandler.On("scanner.registered", (obj) =>
            {
                var scanner = NfcScanner.FromJson(obj as string);
                OnRegistered?.Invoke(scanner);
            });
            _ioHandler.On("scanner.scanned", (obj) =>
            {
                var scanner = NfcScanner.FromJson(obj as string);

            });
        }
開發者ID:hardware-fail,項目名稱:nfc-client-lib-csharp,代碼行數:28,代碼來源:WebNfcListener.cs

示例3: MessageTest

        public void MessageTest()
        {
            var log = LogManager.GetLogger(Global.CallerName());
            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            var count = new[] {0};
            var events = new Queue<object>();

            var options = CreateOptions();
            var uri = CreateUri();
            socket = IO.Socket(uri, options);
            socket.On(Socket.EVENT_CONNECT, () =>
            {
                log.Info("EVENT_CONNECT");
                socket.Emit("hi");
            });

            socket.On("hi",
                (data) =>
                {
                    log.Info("EVENT_MESSAGE");
                    events.Enqueue(data);
                    ManualResetEvent.Set();
                });

            //socket.Open();
            ManualResetEvent.WaitOne();
            socket.Close();
            var obj = events.Dequeue();
            Assert.AreEqual("more data", (string) obj);
        }
開發者ID:rong77,項目名稱:SocketIoClientDotNet,代碼行數:31,代碼來源:ServerConnectionTest.cs

示例4: Connect

        public void Connect()
        {
            var log = LogManager.GetLogger(Global.CallerName());
            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);

            var options = CreateOptions();            
            var uri = CreateUri();

            socket = IO.Socket(uri, options);
            socket.On(Socket.EVENT_CONNECT, () =>
            {
                log.Info("EVENT_CONNECT");
                socket.Disconnect();
            });

            socket.On(Socket.EVENT_DISCONNECT,
                (data) =>
                {
                    log.Info("EVENT_DISCONNECT");
                    Message = (string) data;
                    ManualResetEvent.Set();
                });

            //socket.Open();
            ManualResetEvent.WaitOne();
            socket.Close();
            Assert.Equal("io client disconnect", this.Message);
        }
開發者ID:rong77,項目名稱:SocketIoClientDotNet,代碼行數:29,代碼來源:ServerConnectionTest.cs

示例5: AttachToSocket

 public void AttachToSocket(Socket socket)
 {
     socket.On("Play", Play);
     socket.On("Pause", Pause);
     socket.On("Stop", Stop);
     socket.On("SetTrackId", (id) => SetTrackId((string) id));
 }
開發者ID:musicpicker,項目名稱:MusicPickerDevice,代碼行數:7,代碼來源:HubClient.cs

示例6: initSocket

        private void initSocket(string server)
        {
            socket = IO.Socket(server);

            socket.On(Socket.EVENT_CONNECT, async () =>
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>
                {
                    viewModel.ServerStatus = "Connected";
                }).AsTask();
            });


            socket.On(Socket.EVENT_CONNECT_ERROR, async () =>
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    viewModel.ServerStatus = "Can't connect";
                }).AsTask();
            });

            socket.On(Socket.EVENT_DISCONNECT, async () =>
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    viewModel.ServerStatus = "Not connected";
                }).AsTask();
            });
        }
開發者ID:dwcares,項目名稱:heartrate,代碼行數:29,代碼來源:MainPage.xaml.cs

示例7: SwitchClient

        public SwitchClient(Uri serverUrl)
        {
            this.serverUrl = serverUrl;
            socket = IO.Socket(serverUrl);

            socket.On(Socket.EVENT_CONNECT, OnConnect);
            socket.On(SwitchEvent, OnSwitchEvent);
        }
開發者ID:yuniorb,項目名稱:remote-switch-windows-client,代碼行數:8,代碼來源:SwitchClient.cs

示例8: NewGame

        void NewGame()
        {
            string ten = name.Text;

            if (canvas.Children.Count != 0)
                canvas.Children.Clear();
            game = new GomokuViewModel();
            game.Paint_ChessBoard(canvas);

            // mở kết nối
            if (online)
            {
                socket = IO.Socket(Settings.Default.connectStr);
                socket.On(Socket.EVENT_CONNECT, () =>
                {
                    MessageBox.Show( "Connected");
                    socket.Emit("ChatMessage", "hh");
                    socket.Emit("message:" + "hh", "from:" + "hello");
                });
                socket.On(Socket.EVENT_MESSAGE, (data) =>
                {
                    MessageBox.Show(((JObject)data)["message"].ToString());
                });
                socket.On(Socket.EVENT_CONNECT_ERROR, (data) =>
                {
                    MessageBox.Show(((JObject)data)["message"].ToString());
                });
                socket.On("ChatMessage", (data) =>
                {
                    if (((JObject)data)["message"].ToString() == "Welcome!")
                    {
                        socket.Emit("MyNameIs", ten);
                        socket.Emit("ConnectToOtherPlayer");
                    }
                    // nhận chat
                    if (data.ToString().Contains("from"))
                    {
                        MessageBox.Show(data.ToString());
                    }
                });
                
                socket.On(Socket.EVENT_ERROR, (data) =>
                {
                    MessageBox.Show(((JObject)data)["message"].ToString());
                });
                socket.On("NextStepIs", (data) =>
                {
                    MessageBox.Show(data.ToString());
                });
            }
        }
開發者ID:1312279LeVietKhang,項目名稱:gomoku,代碼行數:51,代碼來源:MainWindow.xaml.cs

示例9: Initialize

        /// <summary>
        /// Initializes the socket and sets-up all the events to listen to.
        /// Server certifaction validation is ingnored, because the server uses a self-signed certificate.
        /// </summary>
        /// <param name="adress"></param>
        public void Initialize(string adress, bool ignoreServerCertificateValidation) {
            _socket = IO.Socket(adress, new IO.Options() { Secure = true, IgnoreServerCertificateValidation = ignoreServerCertificateValidation });

            _socket.On("register-accepted", (data) => {
                Console.WriteLine("Succesfull connected with Server");
            });
            _socket.On("register-failed", (data) => {
                string errorMessage = data.ToString();
                Console.WriteLine("Failed to connected with Server: {0}", errorMessage);
            });
            _socket.On("message", (data) => {
                var message = JsonConvert.DeserializeObject<JsonReceivedMessage>(data.ToString());
                OnMessageReceived(this, new MessageReceivedEventArgs() { Identifier = message.Sender, Message = message.Message, TimeStamp = message.Timestamp, GroupHash = message.GroupHash });
            });
            _socket.On("user-search", (data) => {
                List<Client> clients = JsonConvert.DeserializeObject<List<Client>>(data.ToString());
                OnUserSearch(this, new UserSearchEventArgs() { FoundMembers = clients });
            });
            _socket.On("user-confirm", (data) => {
                var client = JsonConvert.DeserializeObject<Client>(data.ToString());
                OnUserConfirm(this, new UserConfirmEventArgs() { PublicKey = client.PublicKey, UserName = client.UserName });
            });
            _socket.On("joined-group", (data) => {
                var message = JsonConvert.DeserializeObject<JsonJoinedGroup>(data.ToString());
                OnGroupJoined(this, new GroupJoinedEventArgs() { GroupName = message.GroupName, GroupHash = message.GroupHash, Members = message.Members });
            });

            _socket.Connect();
        }
開發者ID:Valentijn1995,項目名稱:Chatty,代碼行數:34,代碼來源:ChattyClient.cs

示例10: connectInternet

        public void connectInternet()
        {
            mSocket = IO.Socket(this.LocalHost);
            if (this.checkConnect == false)
            {
                this.checkConnect = true;
                mSocket.Connect();
            }

            mSocket.On(Socket.EVENT_CONNECT, () =>
            {
                BeginInvoke((Action)(() =>
                {
                    Debug.WriteLine("OK");
                    this.tb_StatusConnection.Text = "Kết nối thành công Internet.!";
                }), null);
            });

            mSocket.On(Socket.EVENT_DISCONNECT, () =>
            {
                BeginInvoke((Action)(() =>
                {
                    this.tb_StatusConnection.Text = "Ngắt kết nối.!";
                }), null);
            });

            mSocket.On("Doc danh sach phong choi", (data) =>
            {
                BeginInvoke((Action)(() =>
                {
                    string[] danhsachphong = data.ToString().Split('|');
                    this.lb_DanhSachPhong.Items.Clear();
                    foreach (var phong in danhsachphong)
                        if (!String.IsNullOrWhiteSpace(phong))
                            this.lb_DanhSachPhong.Items.Add(phong);
                }), null);
            });
        }
開發者ID:PhamPhung,項目名稱:Ver1,代碼行數:38,代碼來源:FormLuaChonCheDoChoi.cs

示例11: connect

        public LinkIO connect(Action listener)
        {
            IO.Options opts = new IO.Options();
            Dictionary<String, String> query = new Dictionary<String, String>();
            query.Add("user", user);

            if(id != "")
                query.Add("id", id);

            opts.Query = query;
            opts.AutoConnect = false;

            socket = IO.Socket("http://" + serverIP, opts);

            socket.On("users", (e) =>
            {
                if (userInRoomChangedListener != null)
                    userInRoomChangedListener.Invoke(((JArray) e).ToObject<List<User>>());
            });

            socket.On(Socket.EVENT_CONNECT, () =>
            {
                connected = true;
                listener.Invoke();
            });

            socket.On(Socket.EVENT_DISCONNECT, () =>
            {
                connected = false;
            });

            socket.On("event", (Object o) =>
            {
                JObject evt = (JObject) o;
                String eventName = (String) evt.SelectToken("type");
                if (eventListeners.ContainsKey(eventName))
                {
                    eventListeners[eventName].Invoke(new Event(evt));
                }                        


            });

            socket.Connect();

            return this;
        }
開發者ID:aragoubi,項目名稱:Nine,代碼行數:47,代碼來源:LinkIOImp.cs

示例12: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            bSend.TouchUpInside += (object sender, EventArgs e) => {
                var message = tfMessage.Text;
                socket.Emit("message", message);
            };

            socket = IO.Socket(Constants.HOST);
            socket.On ("message", (message) => {
                InvokeOnMainThread(() => {
                    var alert = new UIAlertView("From server:", message.ToString(), null, "OK", null);
                    alert.Show();
                });
            });
        }
開發者ID:tudushare,項目名稱:XamarinSocketIODemo,代碼行數:17,代碼來源:MainViewController.cs

示例13: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.Main);

            Button button = FindViewById<Button> (Resource.Id.bSend);
            EditText edit = FindViewById<EditText> (Resource.Id.etMessage);

            button.Click += delegate {
                var message = edit.Text;
                socket.Emit("message", message);
            };

            socket = IO.Socket(Constants.HOST);
            socket.On ("message", delegate(object obj) {
                RunOnUiThread(() => {
                    var message = obj.ToString ();
                    var alert = Toast.MakeText (this, message, ToastLength.Short);
                    alert.Show ();
                });
            });
        }
開發者ID:tudushare,項目名稱:XamarinSocketIODemo,代碼行數:22,代碼來源:MainActivity.cs

示例14: InitSocketConnection

        public void InitSocketConnection()
        {
            socket = Quobject.SocketIoClientDotNet.Client.IO.Socket(server);

            socket.On(Socket.EVENT_CONNECT, () =>
            {
                Console.WriteLine("connected");
                //socket.Emit("hi");

                

            });
            socket.On("msg", o =>
            {
                Console.WriteLine(o.ToString());
            });

            

        }
開發者ID:TNOCS,項目名稱:csTouch,代碼行數:20,代碼來源:Api.cs

示例15: ShouldGetBinaryDataAsAnArraybuffer

        public void ShouldGetBinaryDataAsAnArraybuffer()
        {
            var log = LogManager.GetLogger(Global.CallerName());
            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            var events = new Queue<object>();

            var options = CreateOptions();
            var uri = CreateUri();
            socket = IO.Socket(uri, options);
            socket.On("doge", (data) =>
            {
                events.Enqueue(data);
                ManualResetEvent.Set();
            });

            socket.Emit("doge");

            //socket.Open();
            ManualResetEvent.WaitOne();
            socket.Close();

            var binData = (byte[])events.Dequeue();
            var exptected = System.Text.Encoding.UTF8.GetBytes("asdfasdf");
            var i = 0;
            foreach (var b in exptected)
            {
                Assert.Equal(b, binData[i++]);
            }
        }
開發者ID:rong77,項目名稱:SocketIoClientDotNet,代碼行數:30,代碼來源:ServerConnectionTest.cs


注:本文中的Quobject.SocketIoClientDotNet.Client.Socket.On方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。