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); }
public static DataSocket f_建立OPC连接(string URL, AccessMode _Mode) { DataSocket dataSocket = new DataSocket(); dataSocket.Connect(URL, _Mode); return(dataSocket); }
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); }
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); } }
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); }
public OpcClient(IAirHeaterCom heaterCom, IPidCom pidController) { _heaterCom = heaterCom; _pidController = pidController; _socket = new DataSocket(); StartOpcWriter(); }
/// <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(); }
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(); } }
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); } }
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()); } }
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(); }
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(); } }
internal async Task <uint> WriteAndCloseAsync(IBuffer buffer) { uint bytesWritten = await DataSocket.OutputStream.WriteAsync(buffer); DataSocket.Dispose(); DataSocket = null; return(bytesWritten); }
private void Socket_ConnectionFailedCallback(string error) { Task.Run(() => { socket.Dispose(); socket = null; }); }
public void writeToOPC(bool opcValue) { using (DataSocket ds = new DataSocket()) { ds.Connect(itURL, AccessMode.Write); ds.Data.Value = opcValue; ds.Update(); } }
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); }
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); }
public void Dispose() { if (DataSocket != null) { DataSocket.Dispose(); DataSocket = null; } if (ControlStreamSocket != null) { ControlStreamSocket.Dispose(); ControlStreamSocket = null; } }
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); } }
private void Socket_DisconnectedCallback() { lock (this) { socket.Dispose(); socket = null; } Dispatcher.InvokeAsync(delegate() { SetConnectionUIStates(UIStates.Stopped); }); }
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; } }
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); }
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); } }
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); }
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(); } }
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(); } }
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(); } }
/// <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(); }
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 { } }
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); }
public void SetData(string URL) { this.Data = 链接通道管理.f_建立OPC连接(URL, AccessMode.ReadAutoUpdate); }
public static DataSocket f_建立OPC连接(string URL, AccessMode _Mode) { DataSocket dataSocket = new DataSocket(); dataSocket.Connect(URL, _Mode); return dataSocket; }