Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            int threads;
            threads = Convert.ToInt32(textBox1.Text);
            var done = new CountdownEvent(1);
            ClientLibrary.webSocketForm form = new webSocketForm();
            DateTime current = DateTime.Now;

            Label failedNumber = new Label();
            LogWriter logdata = new LogWriter();
            for (int i = 0; i < threads; i++)
            {
                // RegisterWithWebSocketServer
                ctemp = new SynchronousSocketClient(i, label3, connectedLabel, errorLabel, msgText);
                websocketClients.Add(ctemp);
                ThreadPool.QueueUserWorkItem(ctemp.RegisterWithWebSocketServer, i);
            }
        }
Ejemplo n.º 2
0
        public void RegisterWithWebSocketServer(object connectionID)
        {
            try
            {
                writer = new LogWriter();
                StringBuilder sb = new StringBuilder();
                byte[] bytes = new byte[261120];
                byte[] bytes1 = new byte[10240];
                byte[] data = new byte[0];
                threadIndex = (int)connectionID;
                var serverUri = "ws://192.168.1.159/WebSocketTest/Register";
                _websocket = new WebSocket(serverUri);

                //Raghu: By default EnableAutoSendPing will be true
                // _websocket.EnableAutoSendPing = true;

                _websocket.Opened += new EventHandler(websocket_Opened);
                _websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(websocket_Error);
                _websocket.Closed += new EventHandler(websocket_Closed);
                _websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(websocket_MessageReceived);
                _websocket.DataReceived += new EventHandler<WebSocket4Net.DataReceivedEventArgs>(websocket_DataReceived);
                _websocket.Open();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message + ex.StackTrace);
            }
        }