예제 #1
0
 public static string GetCurrentPicturePath()
 {
     if (State == NowState.Stop)
     {
         throw new VideoSourceDeviceNotWorking();
     }
     else if (State == NowState.LocalCamera)
     {
         FormMain        fm = FormMain.GetInstance();
         TempFileManager _tempFileManager = TempFileManager.GetInstance();
         Image           tempImage        = fm.GetVideoSourcePlayer().GetCurrentVideoFrame();
         string          tempPath         = _tempFileManager.AddTempFile(tempImage);
         return(tempPath);
     }
     else if (State == NowState.TcpIp)
     {
         TcpIpFileManager _tcpIpFileManager = TcpIpFileManager.GetInstance();
         return(_tcpIpFileManager.TcpIpFilePath);
     }
     else
     {
         //Never Reach
         throw new LogicErrorException();
     }
     return(null);
 }
예제 #2
0
 protected FormMain()
 {
     InitializeComponent();
     Control.CheckForIllegalCrossThreadCalls = false;
     _stateManager     = StateManager.GetInstance();
     _tempFileManager  = TempFileManager.GetInstance();
     _tcpIpFileManager = TcpIpFileManager.GetInstance();
 }
예제 #3
0
 public override void Execute(Socket clientSocket)
 {
     try
     {
         byte[] bitLen = new byte[8];
         clientSocket.Receive(bitLen, bitLen.Length, SocketFlags.None);
         //Get the length of the file
         long         contentLen = BitConverter.ToInt64(bitLen, 0);
         int          size       = 0;
         MemoryStream ms         = new MemoryStream();
         //Receive the file
         while (size < contentLen)
         {
             //Receive 256 bytes for every loop
             byte[] bits = new byte[4096];
             int    r    = clientSocket.Receive(bits, bits.Length, SocketFlags.None);
             if (r <= 0)
             {
                 break;
             }
             ms.Write(bits, 0, r);
             size += r;
         }
         System.Drawing.Image img             = System.Drawing.Image.FromStream(ms);
         TcpIpFileManager     tempFileManager = TcpIpFileManager.GetInstance();
         tempFileManager.AddTempFile(img);
         AForgeVideoSourceDevice.VideoSourceDevice.FlashTcpIpImage();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         clientSocket.Shutdown(SocketShutdown.Both);
         clientSocket.Close();
         return;
     }
 }
예제 #4
0
        static void ServerListen(object client)
        {
            TcpManager.TcpClientWithGuid tcpClientWithGuid = (TcpManager.TcpClientWithGuid)client;
            int lostCounter = 0;

            while (true)
            {
                byte[] commandBytes = new byte[8];
                try
                {
                    tcpClientWithGuid.TcpClient.GetStream().Read(commandBytes, 0, commandBytes.Length);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    tcpClientWithGuid.Stop();
                    return;
                }

                long commandType = BitConverter.ToInt64(commandBytes, 0);
                if (commandType == 1)
                {
                    lostCounter = 0;
                    // Receive picture
                    try
                    {
                        byte[] bitLen = new byte[8];
                        tcpClientWithGuid.TcpClient.GetStream().Read(bitLen, 0, bitLen.Length);
                        //Get the length of the file
                        long contentLen = BitConverter.ToInt64(bitLen, 0);
                        if (contentLen > 1000000L)
                        {
                            tcpClientWithGuid.Stop();
                            return;
                        }
                        int          size = 0;
                        MemoryStream ms   = new MemoryStream();
                        //Receive the file
                        while (size < contentLen)
                        {
                            //Receive 256 bytes for every loop
                            byte[] bits = new byte[4096];
                            int    r    = tcpClientWithGuid.TcpClient.GetStream().Read(bits, 0, bits.Length);
                            if (r <= 0)
                            {
                                break;
                            }
                            ms.Write(bits, 0, r);
                            size += r;
                        }
                        System.Drawing.Image img             = System.Drawing.Image.FromStream(ms);
                        TcpIpFileManager     tempFileManager = TcpIpFileManager.GetInstance();
                        tempFileManager.AddTempFile(img);
                        AForgeVideoSourceDevice.VideoSourceDevice.FlashTcpIpImage();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        tcpClientWithGuid.Stop();
                        return;
                    }
                }
                else if (commandType == 0)
                {
                    lostCounter++;
                    if (lostCounter == 100)
                    {
                        tcpClientWithGuid.Stop();
                    }
                }
                else
                {
                    // TODO:Add
                }
            }
        }
예제 #5
0
        private void Receive()
        {
            int          totalPackNumber = 0;
            int          packCount       = 0;
            MemoryStream ms        = new MemoryStream();
            bool         errorSign = false;

            while (true)
            {
                IPEndPoint remote = new IPEndPoint(IPAddress.Any, 0);
                byte[]     data   = _udpClient.Receive(ref remote);

                if (data.Length == 10)
                {
                    string   dataString = Encoding.ASCII.GetString(data);
                    string[] separators = new[] { Separator };
                    string[] items      = dataString.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    if (items[0] == "Picture")
                    {
                        totalPackNumber = Convert.ToInt32(items[1]);
                        packCount       = 0;
                        ms.Flush();
                        ms.Position = 0;
                        errorSign   = false;
                    }
                    else
                    {
                        throw new LogicErrorException();
                    }
                }
                else
                {
                    if (errorSign)
                    {
                        continue;
                    }
                    try
                    {
                        ms.Write(data, 0, data.Length);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        errorSign = true;
                        continue;
                    }

                    packCount++;
                    if (packCount == totalPackNumber)
                    {
                        try
                        {
                            System.Drawing.Image img             = System.Drawing.Image.FromStream(ms);
                            TcpIpFileManager     tempFileManager = TcpIpFileManager.GetInstance();
                            tempFileManager.AddTempFile(img);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            errorSign = true;
                            continue;
                        }
                        AForgeVideoSourceDevice.VideoSourceDevice.FlashTcpIpImage();
                        totalPackNumber = 0;
                    }
                }
            }
        }