Beispiel #1
0
        private void GetClientList(int msgSize, NetworkStream networkStream)
        {
            int msgIndex = 0;
            int startIndex, remainingSize;

            byte[] bytesFrom;
            remainingSize = msgSize;
            bytesFrom     = new byte[msgSize];
            startIndex    = 0;
            try
            {
                while (msgIndex < msgSize)
                {
                    msgIndex += networkStream.Read(bytesFrom, startIndex, remainingSize);
                    if (msgIndex > 0 && msgIndex < msgSize)
                    {
                        remainingSize = msgSize - msgIndex;
                        startIndex    = msgIndex;
                        continue;
                    }
                    else if (0 == msgIndex)
                    {
                        networkStream.Close();
                        return;
                    }
                    string msg = Encoding.ASCII.GetString(bytesFrom);
                    networkStream.Flush();
                    List <string> tempList = msg.Split(',').ToList();
                    tempList.RemoveAt(0);
                    //ClientsList.AddRange(tempList);
                    ClientsList.UnionWith(tempList);
                    log.Write(" .Printing servers List of clients: " + msg);
                }
            }
            catch (ObjectDisposedException)
            {
                throw;
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception ex)
            {
                log.Write("Exception in SendMsgToClient " + ex);
                Console.WriteLine("Exception in SendMsgToClient " + ex);
            }
        }