public MainApplicationContext(int port)
        {
            // init tray icon
            var menuItems = new MenuItem[]
            {
                new MenuItem("Exit", Exit),
            };

            trayIcon = new NotifyIcon()
            {
                Icon        = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location),
                ContextMenu = new ContextMenu(menuItems),
                Visible     = true,
                Text        = "Remote Desktop Server v0.1.0"
            };

            // init input simulation
            input = new InputSimulator();

            // star socket
            dispatcher = Dispatcher.CurrentDispatcher;
            socket     = new DataSocket(NetworkTypes.Server);
            socket.ConnectedCallback         += Socket_ConnectedCallback;
            socket.DisconnectedCallback      += Socket_DisconnectedCallback;
            socket.ConnectionFailedCallback  += Socket_ConnectionFailedCallback;
            socket.DataRecievedCallback      += Socket_DataRecievedCallback;
            socket.StartDataRecievedCallback += Socket_StartDataRecievedCallback;
            socket.EndDataRecievedCallback   += Socket_EndDataRecievedCallback;
            socket.Listen(IPAddress.Any, port);

            // start network discovery
            networkDiscovery = new NetworkDiscovery(NetworkTypes.Server);
            networkDiscovery.Register("SimpleRemoteDesktop", port);
        }
Exemplo n.º 2
0
        public static DataSocket f_建立OPC连接(string URL, AccessMode _Mode)
        {
            DataSocket dataSocket = new DataSocket();

            dataSocket.Connect(URL, _Mode);
            return(dataSocket);
        }
Exemplo n.º 3
0
        protected override void OnClosing(CancelEventArgs e)
        {
            isDisposed = true;

            if (networkDiscovery != null)
            {
                networkDiscovery.Dispose();
                networkDiscovery = null;
            }

            lock (this)
            {
                if (inputTimer != null)
                {
                    inputTimer.Dispose();
                    inputTimer = null;
                }

                if (socket != null)
                {
                    socket.Dispose();
                    socket = null;
                }
            }

            if (gzipStream != null)
            {
                gzipStream.Dispose();
                gzipStream = null;
            }

            settingsOverlay.SaveSettings();
            base.OnClosing(e);
        }
Exemplo n.º 4
0
        public void Connect()
        {
            //if (DebugSocket != null)
            //if(DebugSocket.RemoteEndPoint.Equals(new IPEndPoint(RemoteIpAddress, DebugPort))) DebugSocket.Close();
            if (DataSocket != null)
            {
                if (DataSocket.RemoteEndPoint.Equals(new IPEndPoint(RemoteIpAddress, DataPort)))
                {
                    DataSocket.Close();
                }
            }

            var tcpConnector = new Connector();

            //DebugSocket = tcpConnector.ConnectTo(RemoteIpAddress, DebugPort);
            try
            {
                DataSocket = tcpConnector.ConnectTo(RemoteIpAddress, DataPort);
                OnConnected();
            }
            catch (Exception e)
            {
                Debug.Print(e.Message + e.InnerException);
            }
        }
Exemplo n.º 5
0
        private byte[] GetWebsocketMessageData(WebsocketPipeMessageInfo msg)
        {
            MemoryStream strm = new MemoryStream();

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            try
            {
                DataSocket.WriteMessage(msg, strm);
            }
            catch (Exception ex)
            {
                var str = "Error while writing to data socket: " + ex.Message;
                WriteLogMessage(null, str);
                throw new Exception(str, ex);
            }

            watch.Stop();
            WriteLogTimeMessage(null, "Write to datasocket, ", watch.Elapsed.TotalMilliseconds);

            byte[] data = strm.ToArray();
            strm.Close();
            strm.Dispose();
            return(data);
        }
Exemplo n.º 6
0
 public OpcClient(IAirHeaterCom heaterCom, IPidCom pidController)
 {
     _heaterCom     = heaterCom;
     _pidController = pidController;
     _socket        = new DataSocket();
     StartOpcWriter();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Disconnect from the server.
        /// </summary>
        /// <param name="async">If true then async</param>
        public void Disconnect(bool async = false)
        {
            if (WSServer != null)
            {
                throw new Exception("Cannot both be a server and a client." +
                                    " Please use Disconnect if you are diconnecting from a server or StopListening to stop the server.");
            }

            if (WS == null)
            {
                return;
            }

            if (!WS.IsAlive)
            {
                return;
            }

            if (async)
            {
                WS.CloseAsync();
            }
            else
            {
                WS.Close();
            }

            DataSocket.Close();
        }
Exemplo n.º 8
0
        protected virtual Int32 DataSocketReceiveWhatsAvaiable(Byte[] buffer, Int32 offset, Int32 size)
        {
            this.StartTimeoutTimer();
            try
            {
                Int32 lReadBytes = DataSocket.Receive(buffer, offset, size, SocketFlags.None);

                if (lReadBytes == 0)
                {
                    this.DataSocket.Close();
                }

                this.TriggerOnBytesReceived(lReadBytes);
                return(lReadBytes);
            }
            catch (ObjectDisposedException)
            {
                this.DataSocket.Close();
                return(0);
            }
            catch (SocketException)
            {
                this.DataSocket.Close();
                return(0);
            }
            finally
            {
                this.StopTimeoutTimer();
            }
        }
Exemplo n.º 9
0
 public void writeToOPC(double temperature, double u)
 {
     try
     {
         using (DataSocket ds = new DataSocket())
         {
             if (ds.IsConnected)
             {
                 ds.Disconnect();
             }
             if (tName == "Temperature")
             {
                 ds.Data.Value = temperature;
             }
             else if (tName == "Control")
             {
                 ds.Data.Value = u;
             }
             ds.Connect(itURL, AccessMode.Write);
             ds.Update();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 10
0
 private void DisposePageHavingResources()
 {
     try
     {
         Console.WriteLine("DisposePageHavingResources called!");
         if (player != null)
         {
             // サウンド回りの終了処理はこの呼び出しで全て行われる
             player.togglePlayingTCP();
             player = null;
         }
         if (socket != null)
         {
             // input server および image server との通信に利用しているソケットの終了処理
             Device.BeginInvokeOnMainThread(() =>
             {
                 if (socket != null)
                 {
                     socket.Dispose();
                 }
                 socket = null;
             });
         }
         if (vdecoder != null)
         {
             vdecoder.Close();
             vdecoder = null;
         }
     }catch (Exception e) {
         Console.WriteLine(e.ToString());
     }
 }
Exemplo n.º 11
0
        private void refreshButton_Click(object sender, RoutedEventArgs e)
        {
            // handle stop
            if (uiState == UIStates.Streaming || uiState == UIStates.Paused)
            {
                SetConnectionUIStates(UIStates.Stopped);
                var metaData = new MetaData()
                {
                    type     = MetaDataTypes.PauseCapture,
                    dataSize = -1
                };

                socket.SendMetaData(metaData);

                Thread.Sleep(1000);
                lock (this)
                {
                    socket.Dispose();
                    socket = null;
                }

                return;
            }

            // handle refresh
            refreshingGrid.Visibility = Visibility.Visible;
            var thread = new Thread(Refresh);

            thread.Start();
        }
Exemplo n.º 12
0
        public MainApplicationContext()
        {
            // init tray icon
            var menuItems = new MenuItem[]
            {
                new MenuItem("Exit", Exit),
            };

            trayIcon = new NotifyIcon()
            {
                Icon        = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location),
                ContextMenu = new ContextMenu(menuItems),
                Visible     = true,
                Text        = "Remote Desktop Server v0.1.0"
            };

            dispatcher = Dispatcher.CurrentDispatcher;

            // 重複するコードがあとで実行されるかひとまず置いておく
            // get screen to catpure
            var screens = Screen.AllScreens;
            var screen  = (screenIndex < screens.Length) ? screens[screenIndex] : screens[0];

            screenRect = screen.Bounds;

            if (GlobalConfiguration.isStdOutOff)
            {
                Utils.setStdoutOff();
            }

            if (GlobalConfiguration.isUseFFMPEG)
            {
                kickFFMPEG();
            }

            if (GlobalConfiguration.isEnableImageStreaming || GlobalConfiguration.isEnableInputDeviceController)
            {
                //// start TCP socket listen for image server
                socket = new DataSocket(NetworkTypes.Server);
                socket.ConnectedCallback         += Socket_ConnectedCallback;
                socket.DisconnectedCallback      += Socket_DisconnectedCallback;
                socket.ConnectionFailedCallback  += Socket_ConnectionFailedCallback;
                socket.DataRecievedCallback      += Socket_DataRecievedCallback;
                socket.StartDataRecievedCallback += Socket_StartDataRecievedCallback;
                socket.EndDataRecievedCallback   += Socket_EndDataRecievedCallback;
                //socket.Listen(IPAddress.Parse(GlobalConfiguration.ServerAddress), GlobalConfiguration.ImageAndInputServerPort);
                socket.Listen(IPAddress.Any, GlobalConfiguration.ImageAndInputServerPort);
                if (GlobalConfiguration.isEnableInputDeviceController)
                {
                    input = new InputSimulator();
                }
            }

            // 音声配信サーバ
            if (GlobalConfiguration.isEnableSoundStreaming)
            {
                cap_streamer = new CaptureSoundStreamer();
            }
        }
Exemplo n.º 13
0
        internal async Task <uint> WriteAndCloseAsync(IBuffer buffer)
        {
            uint bytesWritten = await DataSocket.OutputStream.WriteAsync(buffer);

            DataSocket.Dispose();
            DataSocket = null;
            return(bytesWritten);
        }
Exemplo n.º 14
0
 private void Socket_ConnectionFailedCallback(string error)
 {
     Task.Run(() =>
     {
         socket.Dispose();
         socket = null;
     });
 }
Exemplo n.º 15
0
 public void writeToOPC(bool opcValue)
 {
     using (DataSocket ds = new DataSocket())
     {
         ds.Connect(itURL, AccessMode.Write);
         ds.Data.Value = opcValue;
         ds.Update();
     }
 }
Exemplo n.º 16
0
 public void 加载触屏数据()
 {
     U = new DataSocket();
     U.Connect("opc://localhost/National Instruments.NIOPCServers/kaiquan.kaiquan.Anyway.U", AccessMode.WriteAutoUpdate);
     I = new DataSocket();
     I.Connect("opc://localhost/National Instruments.NIOPCServers/kaiquan.kaiquan.Anyway.I", AccessMode.WriteAutoUpdate);
     P = new DataSocket();
     P.Connect("opc://localhost/National Instruments.NIOPCServers/kaiquan.kaiquan.Anyway.P", AccessMode.WriteAutoUpdate);
 }
Exemplo n.º 17
0
 public void 加载触屏数据()
 {
     U = new DataSocket();
     U.Connect("opc://localhost/National Instruments.NIOPCServers/kaiquan.kaiquan.Anyway.U", AccessMode.WriteAutoUpdate);
     I = new DataSocket();
     I.Connect("opc://localhost/National Instruments.NIOPCServers/kaiquan.kaiquan.Anyway.I", AccessMode.WriteAutoUpdate);
     P = new DataSocket();
     P.Connect("opc://localhost/National Instruments.NIOPCServers/kaiquan.kaiquan.Anyway.P", AccessMode.WriteAutoUpdate);
 }
Exemplo n.º 18
0
 public void Dispose()
 {
     if (DataSocket != null)
     {
         DataSocket.Dispose(); DataSocket = null;
     }
     if (ControlStreamSocket != null)
     {
         ControlStreamSocket.Dispose(); ControlStreamSocket = null;
     }
 }
Exemplo n.º 19
0
        public RDPSessionPage()
        {
            NavigationPage.SetHasNavigationBar(this, false);

            //InitializeComponent();

            if (GlobalConfiguration.isStdOutOff)
            {
                Utils.setStdoutOff();
            }

            if (GlobalConfiguration.isEnableImageStreaming || GlobalConfiguration.isEnableInputDeviceController)
            {
                canvas = new SKCanvasView
                {
                    //VerticalOptions = LayoutOptions.FillAndExpand
                    VerticalOptions   = LayoutOptions.Fill,
                    HorizontalOptions = LayoutOptions.Fill
                };
                canvas.PaintSurface += OnCanvasViewPaintSurface;
                // Skiaを利用する場合、ビットマップデータのバッファはここで用意してしまう
                skiaBufStreams = new MemoryStream[2];
                skiaBufStreams.SetValue(new MemoryStream(), 0);
                skiaBufStreams.SetValue(new MemoryStream(), 1);
            }

            Title   = "RDPSession";
            layout  = new AbsoluteLayout();
            Content = layout;

            socket = new DataSocket(NetworkTypes.Client);

            if (GlobalConfiguration.isEnableSoundStreaming && !GlobalConfiguration.isClientRunWithoutConn)
            {
                connectToSoundServer();                                                                                            // start recieve sound data which playing on remote PC
            }
            if (GlobalConfiguration.isEnableInputDeviceController)
            {
                setupInputManager();
            }

            if ((GlobalConfiguration.isEnableImageStreaming || GlobalConfiguration.isEnableInputDeviceController) && !GlobalConfiguration.isClientRunWithoutConn)
            {
                socket.ConnectedCallback         += Socket_ConnectedCallback;
                socket.DisconnectedCallback      += Socket_DisconnectedCallback;
                socket.ConnectionFailedCallback  += Socket_ConnectionFailedCallback;
                socket.DataRecievedCallback      += Socket_DataRecievedCallback;
                socket.StartDataRecievedCallback += Socket_StartDataRecievedCallback;
                socket.EndDataRecievedCallback   += Socket_EndDataRecievedCallback;
                socket.Connect(IPAddress.Parse(GlobalConfiguration.ServerAddress), GlobalConfiguration.ImageAndInputServerPort);
            }
        }
Exemplo n.º 20
0
        private void Socket_DisconnectedCallback()
        {
            lock (this)
            {
                socket.Dispose();
                socket = null;
            }

            Dispatcher.InvokeAsync(delegate()
            {
                SetConnectionUIStates(UIStates.Stopped);
            });
        }
Exemplo n.º 21
0
        public void CreateChannels(List <Channel> channels, string hostAddress)
        {
            foreach (Channel channel in channels)
            {
                DataSocket dataSocket = new DataSocket(this.components);
                ((System.ComponentModel.ISupportInitialize)(dataSocket)).BeginInit();

                ((System.ComponentModel.ISupportInitialize)(dataSocket)).EndInit();

                dataSocket.Url        = "dstp://" + hostAddress + channel.Url;
                dataSocket.AccessMode = NationalInstruments.Net.AccessMode.WriteAutoUpdate;
            }
        }
Exemplo n.º 22
0
        public bool readFromOPC()
        {
            bool OPCvalue = false;

            using (DataSocket ds = new DataSocket())
            {
                ds.Connect(itURL, AccessMode.Read);
                ds.Update();
                OPCvalue = Convert.ToBoolean(ds.Data.Value);
            }

            return(OPCvalue);
        }
Exemplo n.º 23
0
        public void CreateChannels(int numberOfChannel)
        {
            for (int i = 1; i <= numberOfChannel; i++)
            {
                DataSocket dataSocket = new DataSocket(this.components);
                ((System.ComponentModel.ISupportInitialize)(dataSocket)).BeginInit();

                ((System.ComponentModel.ISupportInitialize)(dataSocket)).EndInit();

                dataSocket.Url        = "dstp://localhost/wave" + i.ToString();
                dataSocket.AccessMode = NationalInstruments.Net.AccessMode.WriteAutoUpdate;
                dataSockets.Add(dataSocket);
            }
        }
Exemplo n.º 24
0
        public bool Setup()
        {
            if (Config.Address == 0)
            {
                throw new InvalidOperationException("Configuration address not configured");
            }
            if (Config.Port == 0)
            {
                throw new InvalidOperationException("Configuration port not configured");
            }

            try
            {
                //check if the camera is active
                DataSocket.Connect(new IPEndPoint(Config.Address, Config.Port));
                DataSocket.Send(Encoding.ASCII.GetBytes((int)CameraRequest.Alive + Constants.EndOfMessage));

                //grab data
                byte[] recieveData = new byte[1000];
                int    bytesRec    = DataSocket.Receive(recieveData);
                //if there was no data the camera must have been off
                if (bytesRec <= 0)
                {
                    Console.WriteLine("Camera not active, No data recieved");
                    DataSocket.Shutdown(SocketShutdown.Both);
                    DataSocket.Close();
                    return(false);
                }
                else
                {
                    Console.WriteLine("Camera response = {0}",
                                      Encoding.ASCII.GetString(recieveData, 0, bytesRec - Constants.EndOfMessage.Length));
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("Socket Exception : {0}", e);

                if (!DataSocket.Connected)
                {
                    return(false);
                }

                DataSocket.Shutdown(SocketShutdown.Both);
                DataSocket.Close();
                return(false);
            }

            return(true);
        }
Exemplo n.º 25
0
 public void writeToOPC(bool opcValue)
 {
     using (DataSocket ds = new DataSocket())
     {
         if (ds.IsConnected)
         {
             ds.Disconnect();
         }
         var temp = opcValue;
         ds.Connect(itURL, AccessMode.Write);
         ds.Data.Value = temp;
         ds.Update();
     }
 }
Exemplo n.º 26
0
 protected override int DataSocketReceiveWhatsAvaiable(byte[] aBuffer, int aOffset, int aSize)
 {
     StartTimeoutTimer();
     try
     {
         byte[] tmp    = new byte[aSize];
         int    result = DataSocket.Receive(tmp);
         Array.Copy(tmp, 0, aBuffer, aOffset, result);
         return(result);
     }
     finally
     {
         StopTimeoutTimer();
     }
 }
Exemplo n.º 27
0
        protected virtual Int32 DataSocketSendAsMuchAsPossible(Byte[] buffer, Int32 offset, Int32 size)
        {
            this.StartTimeoutTimer();
            try
            {
                Int32 lSentBytes = DataSocket.Send(buffer, offset, size, SocketFlags.None);

                TriggerOnBytesSent(lSentBytes);

                return(lSentBytes);
            }
            finally
            {
                this.StopTimeoutTimer();
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Listens (and creates a server if needed) to remote connections.
        /// </summary>
        public void Listen()
        {
            if (WS != null)
            {
                throw new Exception("Cannot both be a server and a client." +
                                    " Please use Connect if you are connecting to a server or Listen to create a server.");
            }

            if (WSServer == null)
            {
                MakeServer();
            }

            WSServer.Start();

            DataSocket.Initialize();
        }
        void Exit(object sender, EventArgs e)
        {
            // dispose
            lock (this)
            {
                isDisposed = true;

                if (timer != null)
                {
                    timer.Stop();
                    timer.Tick -= Timer_Tick;
                    timer.Dispose();
                    timer = null;
                }

                if (networkDiscovery != null)
                {
                    networkDiscovery.Dispose();
                    networkDiscovery = null;
                }

                if (socket != null)
                {
                    socket.Dispose();
                    socket = null;
                }

                if (graphics != null)
                {
                    graphics.Dispose();
                    graphics = null;
                }

                if (bitmap != null)
                {
                    bitmap.Dispose();
                    bitmap = null;
                }
            }

            // exit
            trayIcon.Visible = false;
            Application.Exit();
        }
Exemplo n.º 30
0
 public void acceptConnection(object sender, SocketAsyncEventArgs e)
 {
     if (e.SocketError == SocketError.Success)
     {
         Socket s = asyncevent.AcceptSocket;
         if (s != null)
         {
             dataSocket = new NetSocketDataSocket(s);
             state      = 2;
         }
         else
         {
             state = 0;
         }
     }
     else
     {
     }
 }
Exemplo n.º 31
0
        public double readFromOPC()
        {
            double OPCvalue = 0;

            try
            {
                using (DataSocket ds = new DataSocket())
                {
                    ds.Connect(itURL, AccessMode.Read);
                    ds.Update();
                    OPCvalue   = Convert.ToDouble(ds.Data.Value);
                    opcQuality = ds.Data.Attributes["Quality"].Value.ToString();
                }
            }
            catch (Exception ex)
            {
                OPCvalue = 998;
            }
            return(OPCvalue);
        }
Exemplo n.º 32
0
 public void SetData(string URL)
 {
     this.Data = 链接通道管理.f_建立OPC连接(URL, AccessMode.ReadAutoUpdate);
 }
Exemplo n.º 33
0
 public static DataSocket f_建立OPC连接(string URL, AccessMode _Mode)
 {
     DataSocket dataSocket = new DataSocket();
     dataSocket.Connect(URL, _Mode);
     return dataSocket;
 }