예제 #1
0
        protected override void OnStart(string[] args)
        {
            _config = ConfigData.LoadConfig();
            EexcUpdate();
            string name = System.Environment.MachineName;

            win         = new ServiceWindow();
            win.Name    = "TMusic.Service." + name;
            win.Visible = false;
            win.Show();
            listen = new ServerListen();
            listen.Start(_config.Port);
        }
예제 #2
0
 protected override void OnStop()
 {
     if (win != null)
     {
         win.Close();
     }
     if (listen != null)
     {
         listen = null;
     }
     if (sched != null)
     {
         sched.Shutdown(true);
     }
 }
예제 #3
0
        public void CloseServer(bool IsServer)
        {
            if (Client != null)
            {
                Client.Close();
                Client.Dispose();
                if (IsServer)
                {
                    ServerListen.Stop();
                }

                MsgEventArg ms = new MsgEventArg();
                ms._conn = Convert.ToInt32(E.disconnected);
                Updateconnect(ms);
            }
        }
예제 #4
0
        private void Run(object vsc)
        {
            byte[] buffer;
            byte[] imgBuffer = new byte[] { };
            bool   flag      = false;
            int    lastIndex = -1;

            while (true)
            {
                try
                {
                    buffer = ((SocketClient)vsc).client.Receive(ref ((SocketClient)vsc).remotePoint);

                    string strSumLen = Encoding.Default.GetString(buffer, 0, 5);
                    string strIndex  = Encoding.Default.GetString(buffer, 5, 2);
                    int    sumLen    = Int32.Parse(strSumLen);
                    int    index     = Int32.Parse(strIndex);
                    int    allIndex  = sumLen % 1024 > 0 ? sumLen / 1024 + 1 : sumLen / 1024;

                    //若与上一包不连续,并且上一包未完全封装时
                    if (index != lastIndex + 1 && !flag)
                    {
                        //先打包上一包图片
                        Image img = ServerListen.ReadImage(imgBuffer);

                        this.picImage.Image = img;
                        imgBuffer           = new byte[] { };

                        byte[] imgTemp = buffer.Skip(7).ToArray();

                        imgBuffer = imgTemp;

                        flag = false;
                    }
                    //else if (index > lastIndex + 1 && !flag)
                    //{
                    //    //填充丢失包
                    //    for (int i = 0; i < index - (lastIndex+1); i++)
                    //    {
                    //        byte[] imgEmpty = new byte[1024];

                    //        imgBuffer = imgBuffer.Concat(imgEmpty).ToArray();
                    //    }

                    //    byte[] imgTemp = buffer.Skip(7).ToArray();

                    //    imgBuffer = imgBuffer.Concat(imgTemp).ToArray();

                    //    if (index == allIndex)
                    //    {
                    //        Image img = ServerListen.ReadImage(imgBuffer);

                    //        this.picImage.Image = img;
                    //        imgBuffer = new byte[] { };
                    //        flag = true;
                    //    }
                    //    else
                    //    {
                    //        flag = false;
                    //    }
                    //}
                    else
                    {
                        byte[] imgTemp = buffer.Skip(7).ToArray();

                        imgBuffer = imgBuffer.Concat(imgTemp).ToArray();
                        if (index == allIndex)
                        {
                            Image img = ServerListen.ReadImage(imgBuffer);

                            this.picImage.Image = img;
                            imgBuffer           = new byte[] { };
                            flag = true;
                        }
                        else
                        {
                            flag = false;
                        }
                    }

                    lastIndex = index;
                }
                catch
                {
                    imgBuffer = new byte[] { };
                    lastIndex = -1;
                    flag      = false;
                }
            }
        }
예제 #5
0
        private static void Listening(string ip)
        {
            listen = new ServerListen();

            listen.Start(ip, 7777);
        }