internal NullSocketPool( IPEndPoint destination, SocketSettings settings ) : base(destination, settings) { }
/// <summary> /// Create a new SocketClient with a default connection to destination, using the supplied settings. /// </summary> public SocketClient(IPEndPoint destination, SocketSettings settings) { LoadConfig(); mySettings = settings; myEndPoint = destination; this.mySocketPools = SocketManager.Instance.GetSocketPools(settings); this.mySocketPool = GetSocketPool(destination, settings); }
private SocketManager() { _socketPools = new Dictionary<SocketSettings, Dictionary<IPEndPoint, SocketPool>>(2); _defaultSettings = SocketClient.GetDefaultSettings(); Dictionary<IPEndPoint, SocketPool> defaultSettingsPools = new Dictionary<IPEndPoint, SocketPool>(50); _sharedBufferPool = new MemoryStreamPool(_defaultSettings.InitialMessageSize, _defaultSettings.BufferReuses, SocketClient.Config.SharedPoolMinimumItems); _socketPools.Add(_defaultSettings, defaultSettingsPools); }
/// <summary> /// Initiate communication to the remote client and return a stream that can be used to communicate with it. (for acceptor) /// </summary> /// <param name="tcpClient">The TCP client.</param> /// <param name="settings">The socket settings.</param> /// <param name="logger">Logger to use.</param> /// <returns>an opened and initiated stream which can be read and written to</returns> /// <exception cref="System.ArgumentException">tcp client must be connected in order to get stream;tcpClient</exception> public static Stream CreateServerStream(TcpClient tcpClient, SocketSettings settings, ILog logger) { if (tcpClient.Connected == false) throw new ArgumentException("tcp client must be connected in order to get stream", "tcpClient"); Stream stream = tcpClient.GetStream(); if (settings.UseSSL) { stream = new SSLStreamFactory(logger, settings) .CreateServerStreamAndAuthenticate(stream); } return stream; }
internal ManagedSocket(SocketSettings settings, SocketPool socketPool) : base(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) { this.CreatedTicks = DateTime.UtcNow.Ticks; this.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, settings.SendBufferSize); this.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, settings.ReceiveBufferSize); this.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, settings.SendTimeout); this.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, settings.ReceiveTimeout); this.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1); this.settings = settings; buildSocketCallBack = new AsyncCallback(BuildSocketCallBack); receiveCallBack = new AsyncCallback(ReceiveCallback); this.myPool = socketPool; }
/// <summary> /// Connect to the specified endpoint and return a stream that can be used to communicate with it. (for initiator) /// </summary> /// <param name="endpoint">The endpoint.</param> /// <param name="settings">The socket settings.</param> /// <param name="logger">Logger to use.</param> /// <returns>an opened and initiated stream which can be read and written to</returns> public static Stream CreateClientStream(IPEndPoint endpoint, SocketSettings settings, ILog logger) { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.NoDelay = settings.SocketNodelay; socket.Connect(endpoint); Stream stream = new NetworkStream(socket, true); if (settings.UseSSL) { stream = new SSLStreamFactory(logger, settings) .CreateClientStreamAndAuthenticate(stream); } return stream; }
internal Dictionary<IPEndPoint, SocketPool> GetSocketPools(SocketSettings settings) { Dictionary<IPEndPoint, SocketPool> poolsForSettings; if (!_socketPools.TryGetValue(settings, out poolsForSettings)) { lock (_socketPools) { if (!_socketPools.TryGetValue(settings, out poolsForSettings)) { poolsForSettings = new Dictionary<IPEndPoint, SocketPool>(50); _socketPools.Add(settings, poolsForSettings); return poolsForSettings; } } } return poolsForSettings; }
internal SocketPool( IPEndPoint destination, SocketSettings settings ) { this.destination = destination; poolSize = settings.PoolSize; Settings = settings; TimeSpan socketLifetime = new TimeSpan(0, 0, settings.SocketLifetimeMinutes, 0, 0); socketLifetimeTicks = socketLifetime.Ticks; if (SocketClient.Config.UseSharedBufferPool) { rebufferedStreamPool = SocketManager.Instance.SharedBufferPool; } else { rebufferedStreamPool = new MemoryStreamPool(settings.InitialMessageSize, settings.BufferReuses); } }
private static SocketPool BuildSocketPool(IPEndPoint destination, SocketSettings settings) { return SocketManager.BuildSocketPool(destination, settings); }
public SocketFactory(string address, SocketType socketType, SocketSettings settings) { _address = address; _socketType = socketType; _settings = settings; }
public SSLStreamFactory(ILog log, SocketSettings settings) { log_ = log; socketSettings_ = settings; }
internal void GetSocketCounts(IPEndPoint destination, SocketSettings settings, out int totalSockets, out int activeSockets) { SocketPool pool = GetSocketPool(destination, settings); activeSockets = pool.activeSocketCount; totalSockets = pool.socketCount; }
internal SocketPool GetSocketPool(IPEndPoint destination, SocketSettings settings) { Dictionary<IPEndPoint, SocketPool> pools = GetSocketPools(settings); SocketPool pool; if (!pools.TryGetValue(destination, out pool)) { lock (pools) { if (!pools.TryGetValue(destination, out pool)) { pool = BuildSocketPool(destination, settings); pools.Add(destination, pool); } } } return pool; }
public EnableLogging(SocketSettings socketSettings) : base(socketSettings) { }
public ScrollMouse(SocketSettings socketSettings, float speed, float duration) : base(socketSettings) { this.speed = speed; this.duration = duration; }
public SocketListener(SocketSettings socketSettings) { this.socketSettings = socketSettings; this.prefixHandler = new PrefixHandler(); this.messageHandler = new MessageHandler(); this.bufferManager = new BufferManager(this.socketSettings.BufferSize * this.socketSettings.NumOfSaeaForRecSend, this.socketSettings.BufferSize); this.ioEventArgsPool = new ThreadSafeStack<SocketAsyncEventArgs>(socketSettings.NumOfSaeaForRecSend); this.acceptEventArgsPool = new ThreadSafeStack<SocketAsyncEventArgs>(socketSettings.MaxAcceptOps); this.maxConnectionsEnforcer = new Semaphore(this.socketSettings.MaxConnections, this.socketSettings.MaxConnections); Init(); expireTimer = new Timer(CheckExpire, null, socketSettings.ExpireInterval, socketSettings.ExpireInterval); }
public PressKeyAndWait(SocketSettings socketSettings, Assets.AltUnityTester.AltUnityDriver.UnityStruct.KeyCode keyCode, float power, float duration) : base(socketSettings) { this.keyCode = keyCode; this.power = power; this.duration = duration; }
public TapScreen(SocketSettings socketSettings, float x, float y) : base(socketSettings) { this.x = x; this.y = y; }
public void Setup() { _generateLogFiles = false; _clientLogMessages = new List <string>(); _serverLogMessages = new List <string>(); _remoteServerFolderPath = string.Empty; _remoteServerLocalIp = null; _remoteServerPublicIp = null; _serverReceivedTextMessage = false; _serverFileTransferPending = false; _serverReceivedAllFileBytes = false; _serverConfirmedFileTransferComplete = false; _serverRejectedFileTransfer = false; _serverProcessingRequestBacklogStarted = false; _serverProcessingRequestBacklogComplete = false; _serverErrorOccurred = false; _serverSendFileBytesStarted = false; _serverSendFileBytesComplete = false; _serverStoppedSendingFileBytes = false; _serverWasNotifiedFileTransferStalled = false; _clientReceivedTextMessage = false; _clientFileTransferPending = false; _clientReceiveFileBytesStarted = false; _clientReceiveFileBytesComplete = false; _clientConfirmedFileTransferComplete = false; _clientRejectedFileTransfer = false; _clientProcessingRequestBacklogStarted = false; _clientProcessingRequestBacklogComplete = false; _clientErrorOccurred = false; _clientReceivedServerInfo = false; _clientReceiveFileBytesComplete = false; _clientWasNotifiedFolderIsEmpty = false; _clientWasNotifiedFolderDoesNotExist = false; _clientWasNotifiedRetryLimitExceeded = false; _clientWasNotifiedFileDoesNotExist = false; _fileInfoList = new FileInfoList(); var currentPath = Directory.GetCurrentDirectory(); var index = currentPath.IndexOf("bin", StringComparison.Ordinal); _testFilesFolder = $"{currentPath.Remove(index - 1)}{Path.DirectorySeparatorChar}TestFiles{Path.DirectorySeparatorChar}"; _localFolder = _testFilesFolder + $"Client{Path.DirectorySeparatorChar}"; _remoteFolder = _testFilesFolder + $"Server{Path.DirectorySeparatorChar}"; _emptyFolder = _testFilesFolder + $"EmptyFolder{Path.DirectorySeparatorChar}"; _tempFolder = _testFilesFolder + $"temp{Path.DirectorySeparatorChar}"; Directory.CreateDirectory(_localFolder); Directory.CreateDirectory(_remoteFolder); Directory.CreateDirectory(_emptyFolder); _localFilePath = _localFolder + FileName; _remoteFilePath = _remoteFolder + FileName; _restoreFilePath = _testFilesFolder + FileName; FileHelper.DeleteFileIfAlreadyExists(_localFilePath, 3); if (File.Exists(_restoreFilePath)) { File.Copy(_restoreFilePath, _localFilePath); } FileHelper.DeleteFileIfAlreadyExists(_remoteFilePath, 3); if (File.Exists(_restoreFilePath)) { File.Copy(_restoreFilePath, _remoteFilePath); } _cidrIp = "172.20.10.0/28"; _remoteServerPlatform = ServerPlatform.None; var getCidrIp = NetworkUtilities.GetCidrIp(); if (getCidrIp.Success) { _cidrIp = getCidrIp.Value; } _cts = new CancellationTokenSource(); _socketSettings = new SocketSettings { ListenBacklogSize = 5, BufferSize = 1024, SocketTimeoutInMilliseconds = 10000 }; _clientSettings = new ServerSettings { LocalServerFolderPath = _localFolder, LocalNetworkCidrIp = _cidrIp, SocketSettings = _socketSettings, TransferUpdateInterval = 0.10f, FileTransferStalledTimeout = TimeSpan.FromSeconds(5), TransferRetryLimit = 2, RetryLimitLockout = TimeSpan.FromSeconds(3), LogLevel = LogLevel.Info }; _serverSettings = new ServerSettings { LocalServerFolderPath = _remoteFolder, LocalNetworkCidrIp = _cidrIp, SocketSettings = _socketSettings, TransferUpdateInterval = 0.10f, FileTransferStalledTimeout = TimeSpan.FromSeconds(5), TransferRetryLimit = 2, RetryLimitLockout = TimeSpan.FromSeconds(3), LogLevel = LogLevel.Info }; }
public FakeSocket(SocketSettings settings, IVSLCallback callback) : base(settings, callback) { Channel = new NetworkChannel(new Socket(SocketType.Stream, ProtocolType.Tcp), ExceptionHandler, CreateFakeCache()); }
internal ArraySocketPool(IPEndPoint destination, SocketSettings settings) : base(destination, settings) { sockets = new ArrayManagedSocket[this.poolSize]; }
public GetAllCameras(SocketSettings socketSettings) : base(socketSettings) { }
internal static SocketPool BuildSocketPool(IPEndPoint destination, SocketSettings settings) { switch (settings.PoolType) { case SocketPoolType.Array: return new ArraySocketPool(destination, settings); case SocketPoolType.Null: return new NullSocketPool(destination, settings); case SocketPoolType.Linked: return new LinkedManagedSocketPool(destination, settings); default: return new ArraySocketPool(destination, settings); } }
public FindElementsWhereNameContains(SocketSettings socketSettings, string name, string cameraName, bool enabled) : base(socketSettings) { this.name = name; this.cameraName = cameraName; this.enabled = enabled; }
internal ManagedSocket GetSocket(IPEndPoint destination, SocketSettings settings) { return GetSocketPool(destination, settings).GetSocket(); }
public TcpSocketClientWithDisposeDetection(SocketSettings socketSettings, ILogger logger = null) : base(socketSettings, logger) { }
public RequestReceiver(SocketSettings settings) { _settings = settings; }
/// <summary> /// Called by XmlSerializationSectionHandler when the config is reloaded. /// </summary> public void ReloadConfig(object sender, EventArgs args) { SocketClientConfig newConfig = GetConfig(); if (mySettings == defaultMessageSettings) //current using defaults, if defaults change we want to change the active socket pool { if (!newConfig.DefaultSocketSettings.SameAs(defaultMessageSettings)) //settings have changed, need to change "mySocketPool(s)" reference { if (log.IsInfoEnabled) log.Info("Default socket settings changed, updating default socket pool."); mySocketPools = SocketManager.Instance.GetSocketPools(newConfig.DefaultSocketSettings); if (mySocketPool != null && myEndPoint != null) { SocketPool oldDefault = mySocketPool; mySocketPool = GetSocketPool(myEndPoint, newConfig.DefaultSocketSettings); oldDefault.ReleaseAndDisposeAll(); } } mySettings = newConfig.DefaultSocketSettings; } defaultMessageSettings = newConfig.DefaultSocketSettings; config = newConfig; }
/// <summary> /// Sends a message to a server that does not expect a reply. /// </summary> /// <param name="destination">The server's EndPoint</param> /// <param name="messageSettings">Settings for the transport.</param> /// <param name="commandID">The Command Identifier to send to the server. The server's IMessageHandler should know about all possible CommandIDs</param> /// <param name="messageStream">The contents of the message for the server to process.</param> public void SendOneWay(IPEndPoint destination, SocketSettings messageSettings, int commandID, MemoryStream messageStream) { SocketPool socketPool = GetSocketPool(destination, messageSettings); SendOneWay(socketPool, commandID, messageStream); }
/// <summary> /// Sends a message to the server that expects a response. /// </summary> /// <param name="destination">The server's EndPoint</param> /// <param name="messageSettings">The settings to use for the transport.</param> /// <param name="commandID">The Command Identifier to send to the server. The server's IMessageHandler should know about all possible CommandIDs</param> /// <param name="messageStream">The contents of the message for the server to process.</param> /// <returns>The object returned by the server, if any.</returns> public MemoryStream SendSync(IPEndPoint destination, SocketSettings messageSettings, int commandID, MemoryStream messageStream) { SocketPool pool = SocketManager.Instance.GetSocketPool(destination, messageSettings); MemoryStream replyStream = SendSync(pool, commandID, messageStream); return replyStream; }
public GetPNGScreenshot(SocketSettings socketSettings, string path) : base(socketSettings) { this.path = path; }
public Tap(SocketSettings socketSettings, AltUnityObject altUnityObject) : base(socketSettings) { this.altUnityObject = altUnityObject; }
private void LoadConfig() { SocketClientConfig config = Config; this.defaultMessageSettings = config.DefaultSocketSettings; XmlSerializerSectionHandler.RegisterReloadNotification(typeof(SocketClientConfig), new EventHandler(ReloadConfig)); }
public WaitForCurrentSceneToBe(SocketSettings socketSettings, string sceneName, double timeout, double interval) : base(socketSettings) { this.sceneName = sceneName; this.timeout = timeout; this.interval = interval; }
/// <summary> /// Get the number of sockets created and in use for a given destination and settings combination. /// </summary> /// <param name="destination">The server endpoint to check for.</param> /// <param name="settings">The settings object portion of the pool key.</param> /// <param name="totalSockets">The number of sockets created.</param> /// <param name="activeSockets">The number of active sockets.</param> public void GetSocketCounts(IPEndPoint destination, SocketSettings settings, out int totalSockets, out int activeSockets) { SocketManager.Instance.GetSocketCounts(destination, settings, out totalSockets, out activeSockets); }
public PointerDownFromObject(SocketSettings socketSettings, AltUnityObject altUnityObject) : base(socketSettings) { this.altUnityObject = altUnityObject; }
/// <summary> /// Create a new SocketClient for connecting to any number of servers with any settings. /// </summary> public SocketClient() { LoadConfig(); mySettings = defaultMessageSettings; this.mySocketPools = SocketManager.Instance.GetSocketPools(defaultMessageSettings); }
public GetCurrentScene(SocketSettings socketSettings) : base(socketSettings) { }
private static SocketPool GetSocketPool(IPEndPoint destination, SocketSettings settings) { return SocketManager.Instance.GetSocketPool(destination, settings); }
public Swipe(SocketSettings socketSettings, Vector2 start, Vector2 end, float duration) : base(socketSettings) { this.start = start; this.end = end; this.duration = duration; }
/// <summary> /// Create a new SocketClient that will use the supplied settings for all messages. /// </summary> /// <param name="settings"></param> public SocketClient(SocketSettings settings) { LoadConfig(); mySettings = settings; this.mySocketPools = SocketManager.Instance.GetSocketPools(settings); }
public MoveMouse(SocketSettings socketSettings, Vector2 location, float duration) : base(socketSettings) { this.location = location; this.duration = duration; }
internal ArrayManagedSocket(SocketSettings settings, SocketPool pool, int index) : base(settings, pool) { this.Index = index; }
public WebSocket(System.Net.WebSockets.WebSocket socket, SocketSettings settings, ILoggerFactory loggerFactory) : base(settings, loggerFactory.CreateLogger(nameof(WebSocket))) { _webSocket = socket; SetState(); }
public SocketProxy(GSConnectionManager gsConnectionManager) { this.gsConnectionManager = gsConnectionManager; IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, ListenPort); var socketSettings = new SocketSettings(maxConnections, backlog, maxAcceptOps, bufferSize, localEndPoint, expireInterval, expireTime); listener = new SocketListener(socketSettings); listener.DataReceived += new ConnectionEventHandler(socketLintener_DataReceived); listener.Connected += new ConnectionEventHandler(socketLintener_Connected); listener.Disconnected += new ConnectionEventHandler(socketLintener_Disconnected); listener.StartListen(); Logger.Info("TCP监听启动,端口号:{0}。", ListenPort); timer = new Timer(Check, null, proxyCheckPeriod, proxyCheckPeriod); }
public SetText(SocketSettings socketSettings, AltUnityObject altUnityObject, string text) : base(socketSettings) { this.altUnityObject = altUnityObject; this.newText = text; }