Ejemplo n.º 1
0
            public void ToClientThread()
            {
                int nRecv;

                byte[] buffer = new byte[1024];
                //string strMsg;
                MemoryStream msPic = null;
                string       strPicHeader;

                //string[] strRequests;
                while (true)
                {
                    try
                    {
                        nRecv = m_socket.Receive(buffer);
                    }
                    catch (SocketException)
                    {
                        break;
                    }
                    if (nRecv <= 0)
                    {
                        break;
                    }

                    msPic = m_parent.PictureData;
                    if (msPic == null)
                    {
                        break;
                    }
                    try
                    {
                        m_socket.Send(Encoding.ASCII.GetBytes(strStreamHeader));
                        while (m_server.m_bRunning)
                        {
                            strPicHeader = string.Format(strPicHeaderFormat, msPic.Length);
                            m_socket.Send(Encoding.ASCII.GetBytes(strPicHeader));
                            m_socket.Send(msPic.ToArray());
                            Thread.Sleep(40);
                            msPic = m_parent.PictureData;
                            if (msPic == null)
                            {
                                break;
                            }
                        }
                    }
                    catch (SocketException)
                    {
                        break;
                    }
                    break;
                    //strMsg = Encoding.ASCII.GetString(buffer, 0, nRecv);
                    //strRequests = strMsg.Split(new string[] { "\r\n" }, 10, StringSplitOptions.RemoveEmptyEntries);
                    //m_server.AddMessage(strMsg);
                }
                m_socket.Close();
                m_server.DeleteClient(this);
            }