Пример #1
0
        // Listen for messages
        private void listen()
        {
            while (isConnected)
            {
                NetworkStream nStream       = tcpCon.GetStream();
                StreamReader  nStreamReader = new StreamReader(nStream);

                string read;
                try
                {
                    read = nStreamReader.ReadLine();
                }
                catch (IOException)
                {
                    Console.WriteLine("Socket read interruptet, assuming connection is beeing closed");
                    return;
                }

                Console.WriteLine("Worker: Received: " + read);

                ComDataToClient comData = new ComDataToClient();
                comData.FromXML(read);

                // Handle new message
                ComDataReceivedEvent(comData);
            }

            ConnectionChangedEvent();
        }
        // Handle received data
        private void DataReceived(ComData comData)
        {
            ComDataToClient c = (ComDataToClient)comData;

            if (comData.message != "" && comData.message != null)
            {
                AddLogEntry("[" + comData.name + "] " + comData.message);
            }

            if (c.filename != "" && c.filename != null && c.start != null && c.end != null)
            {
                GotWork(c.filename, c.start, c.end, c.lower, c.upper, c.numbers, c.symbols);
            }
        }
Пример #3
0
        // Send workorder to a client
        public void SendWorkOrder(int clientId, string file, char[] start, char[] end, bool lower, bool upper, bool numbers, bool symbols)
        {
            ComDataToClient comData = new ComDataToClient();

            comData.message  = "";
            comData.filename = file;
            comData.start    = new string(start);
            comData.end      = new string(end);
            comData.lower    = lower;
            comData.upper    = upper;
            comData.numbers  = numbers;
            comData.symbols  = symbols;

            Send(comData, clientId);
        }
        // Add a chat entry, and echo it to the clients
        private void AddChatEntry(string message, string name)
        {
            if (message != "" && message != null)
            {
                string msg = "[" + name + "] " + message;
                AddLogEntry(msg);
            }

            ComData cd = new ComDataToClient();

            cd.message = message;
            cd.name    = name;

            // Echo...
            listener.Send(cd);
        }
        // Send only to selected
        private void btnSendToSelected_Click(object sender, RoutedEventArgs e)
        {
            foreach (ListBoxItem item in lstClients.SelectedItems)
            {
                string selectedItem = item.Content.ToString();
                Int32.TryParse(selectedItem.Substring(selectedItem.LastIndexOf("ID: ")).Replace("ID: ", ""), out int clientID);

                string clientName = listener.GetNameFromID(clientID);
                string msg        = "[Server -> " + clientName + "] " + txtSend.Text;

                ComData cd = new ComDataToClient();
                cd.message = msg;

                if (msg != "" && msg != null)
                {
                    AddLogEntry(msg);
                }
                listener.Send(cd, clientID);
            }

            string selected = lstClients.SelectedItems.ToString();
        }