/// <summary> /// Creates and connects the connection. Only uses one controller (chat). This method /// is called from SignInButton_Click. /// </summary> private async void Connect() { Connection = new XSocketClient(ServerURI, Origin, "chat"); Connection.OnDisconnected += Connection_Disconnected; chatController = Connection.Controller("chat"); //Handle incoming event from server: use Invoke to write to console from XSocket's thread chatController.On <string>("addMessage", message => this.Invoke((Action)(() => RichTextBoxConsole.AppendText(String.Format("{0}" + Environment.NewLine, message)) ))); try { Connection.Open(); comboBoxLocation.SelectedIndex = 0; //Set username chatController.SetProperty("username", UserName); } catch { StatusText.Text = "Unable to connect to server: Start server before connecting clients."; //No connection: Don't enable Send button or show chat UI return; } //Activate UI SignInPanel.Visible = false; ChatPanel.Visible = true; ButtonSend.Enabled = true; TextBoxMessage.Focus(); RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + Environment.NewLine); }
public static void Main() { _client = new XSocketClient("127.0.0.1", 4502, "JsonProtocol", "Welcome to JsonProtocol"); _client.OnOpen += (sender, args) => { Debug.Print("Connected"); // Tell the server that I am a Netduino _client.SetEnum("Hardware", "Netduino", "Sensor"); //Start sending fake sensor data sensorThread = new Thread(Sensor); sensorThread.Start(); }; _client.OnClose += (sender, args) => { Debug.Print("Closed"); sensorThread.Suspend(); }; //Listen for messages _client.OnMessage += _client_OnMessage; //Open connection _client.Open(); //Prevent exit since that would stop the program Thread.Sleep(Timeout.Infinite); }
public static void Main() { _client = new XSocketClient("127.0.0.1", 4502, "JsonProtocol", "Welcome to JsonProtocol"); _client.OnOpen += (sender, args) => { Debug.Print("Connected"); // Tell the server that I am a Netduino _client.SetEnum("Hardware","Netduino","Sensor"); //Start sending fake sensor data sensorThread = new Thread(Sensor); sensorThread.Start(); }; _client.OnClose += (sender, args) => { Debug.Print("Closed"); sensorThread.Suspend(); }; //Listen for messages _client.OnMessage += _client_OnMessage; //Open connection _client.Open(); //Prevent exit since that would stop the program Thread.Sleep(Timeout.Infinite); }
/// <summary> /// Creates and connects the hub connection and hub proxy. This method /// is called asynchronously from SignInButton_Click. /// </summary> private async void ConnectAsync() { Connection = new XSocketClient(ServerURI, Origin, "chat"); Connection.OnDisconnected += Connection_Disconnected; chatController = Connection.Controller("chat"); //Handle incoming event from server: use Invoke to write to console from XSocket's thread chatController.On <string>("AddMessage", (message) => this.Dispatcher.Invoke(() => RichTextBoxConsole.AppendText(String.Format("{0}\r", message)) ) ); try { await Connection.Open(); //Set username await chatController.SetProperty("username", UserName); } catch { StatusText.Content = "Unable to connect to server: Start server before connecting clients."; //No connection: Don't enable Send button or show chat UI return; } //Show chat UI; hide login UI SignInPanel.Visibility = Visibility.Collapsed; ChatPanel.Visibility = Visibility.Visible; ButtonSend.IsEnabled = true; TextBoxMessage.Focus(); RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + "\r"); }
/// <summary> /// Creates and connects the connection. Only uses one controller (chat). This method /// is called from SignInButton_Click. /// </summary> private async void Connect() { Connection = new XSocketClient(ServerURI,Origin,"chat"); Connection.OnDisconnected += Connection_Disconnected; chatController = Connection.Controller("chat"); //Handle incoming event from server: use Invoke to write to console from XSocket's thread chatController.On<string>("addMessage", message => this.Invoke((Action) (() => RichTextBoxConsole.AppendText(String.Format("{0}" + Environment.NewLine, message)) ))); try { Connection.Open(); comboBoxLocation.SelectedIndex = 0; //Set username chatController.SetProperty("username", UserName); } catch { StatusText.Text = "Unable to connect to server: Start server before connecting clients."; //No connection: Don't enable Send button or show chat UI return; } //Activate UI SignInPanel.Visible = false; ChatPanel.Visible = true; ButtonSend.Enabled = true; TextBoxMessage.Focus(); RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + Environment.NewLine); }
/// <summary> /// Creates and connects the hub connection and hub proxy. This method /// is called asynchronously from SignInButton_Click. /// </summary> private async void ConnectAsync() { Connection = new XSocketClient(ServerURI, Origin, "chat"); Connection.OnDisconnected += Connection_Disconnected; chatController = Connection.Controller("chat"); //Handle incoming event from server: use Invoke to write to console from XSocket's thread chatController.On<string>("AddMessage", (message) => this.Dispatcher.Invoke(() => RichTextBoxConsole.AppendText(String.Format("{0}\r", message)) ) ); try { Connection.Open(); //Set username chatController.SetProperty("username", UserName); } catch { StatusText.Content = "Unable to connect to server: Start server before connecting clients."; //No connection: Don't enable Send button or show chat UI return; } //Show chat UI; hide login UI SignInPanel.Visibility = Visibility.Collapsed; ChatPanel.Visibility = Visibility.Visible; ButtonSend.IsEnabled = true; TextBoxMessage.Focus(); RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + "\r"); }
public static void Main() { //Change this ip to the IP of your machine (where XSockets is running) _conn = new XSocketClient("192.168.1.2", 4502); _conn.OnOpen += ConnOnOpen; _conn.OnClose += ConnOnClose; _conn.OnMessage += ConnOnMessage; _conn.Open(); Thread.Sleep(Timeout.Infinite); }