Example #1
0
 /// <summary>
 /// OnClose event handler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private static void WebSocket_OnClose(object sender, CloseEventArgs e)
 {
     ConnectStatus.SetText("Disconnected");
     ServerConsole.Disable();
     PlayerCounter.Reset();
     Update.StopThreads();
 }
Example #2
0
        /// <summary>
        /// Disconnects the websocket
        /// </summary>
        public static void Disconnect()
        {
            if (!IsConnected())
            {
                MessageBox.Show("You aren't connected.", "Sharpcon", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            ConnectStatus.SetText("Disconnecting...");
            webSocket.CloseAsync();
        }
Example #3
0
        /// <summary>
        /// Connects the websocket while attaching the event handlers
        /// </summary>
        public static void Connect()
        {
            if (IsConnected())
            {
                MessageBox.Show("You're already connected.", "Sharpcon", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            ConnectStatus.SetText("Connecting...");
            webSocket            = new WebSocket($"ws://{Form1.Settings.ServerAddress}:{Form1.Settings.ServerPort}/{Form1.Settings.ServerPassword}");
            webSocket.OnOpen    += WebSocket_OnOpen;
            webSocket.OnMessage += WebSocket_OnMessage;
            webSocket.OnError   += WebSocket_OnError;
            webSocket.OnClose   += WebSocket_OnClose;
            webSocket.ConnectAsync();
        }
Example #4
0
 /// <summary>
 /// OnOpen event handler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private static void WebSocket_OnOpen(object sender, EventArgs e)
 {
     ConnectStatus.SetText("Connected");
     ServerConsole.Enable();
     Update.StartThreads();
 }