public async Task UpgradeToSecureAsServerAndClientAsync_ReturnTrue() { Assert.Ignore(); var tempPath = System.IO.Path.GetTempPath() + "certificate.pfx"; var certificate = Mocks.CertificateHelper.CreateOrLoadCertificate(tempPath, Localhost, "password"); ConnectionListener.Start(); await Client.ConnectAsync(Localhost, Port); ConnectionListener.OnConnectionAccepting += (s, e) => { using (var cn = new Connection(e.Client)) { cn.UpgradeToSecureAsServerAsync(certificate).Wait(); } }; using (var cn = new Connection(Client)) { var result = await cn.UpgradeToSecureAsClientAsync(); Assert.IsTrue(result); Assert.IsTrue(cn.IsActiveStreamSecure); } }
public async Task Connect_Success(bool clientFirst) { await using ConnectionFactory factory = new MemoryConnectionFactory(); await using ConnectionListener listener = await factory.ListenAsync(); using var semaphore = new SemaphoreSlim(0); await RunClientServer(async () => { if (!clientFirst) { bool success = await semaphore.WaitAsync(10_000); Assert.True(success); } ValueTask<Connection> task = factory.ConnectAsync(listener.EndPoint!); if (clientFirst) semaphore.Release(); await using Connection connection = await task; }, async () => { if (clientFirst) { bool success = await semaphore.WaitAsync(10_000); Assert.True(success); } ValueTask<Connection?> task = listener.AcceptConnectionAsync(); if (!clientFirst) semaphore.Release(); await using Connection? connection = await task; Assert.NotNull(connection); }); }
public async Task OnConnectionAcceptingTest() { const int port = 12345; using (var connectionListener = new ConnectionListener(port)) { using (var client = new TcpClient()) { var isAccepting = false; connectionListener.Start(); connectionListener.OnConnectionAccepting += (s, e) => { Assert.IsTrue(e.Client.Connected); isAccepting = true; }; await client.ConnectAsync("localhost", port); await Task.Delay(100); Assert.IsTrue(connectionListener.IsListening); Assert.IsTrue(client.Connected); Assert.IsTrue(isAccepting); client.Close(); } connectionListener.Stop(); } }
public async Task OnConnectionAcceptedTest() { const int port = 12347; using (var connectionListener = new ConnectionListener(port)) { using (var client = new TcpClient()) { var isAccepted = false; connectionListener.OnConnectionAccepted += (s, e) => { isAccepted = true; }; connectionListener.Start(); await client.ConnectAsync("localhost", port); await Task.Delay(100); Assert.IsTrue(connectionListener.IsListening, "Connection Listerner is listening"); Assert.IsTrue(client.Connected, "Client is connected"); Assert.IsTrue(isAccepted, "The flag was set"); client.Close(); } connectionListener.Stop(); } }
public static void Initialize() { var hosts = new List <IPAddress>(); try { var splits = ConfigManager.Config.Server.Network.Host.Split(","); foreach (var split in splits) { hosts.Add(IPAddress.Parse(split)); } } catch (Exception ex) { log.Error($"Unable to use {ConfigManager.Config.Server.Network.Host} as host due to: {ex}"); log.Error("Using IPAddress.Any as host instead."); hosts.Clear(); hosts.Add(IPAddress.Any); } listeners = new ConnectionListener[hosts.Count * 2]; for (int i = 0; i < hosts.Count; i++) { listeners[(i * 2) + 0] = new ConnectionListener(hosts[i], ConfigManager.Config.Server.Network.Port); log.Info($"Binding ConnectionListener to {hosts[i]}:{ConfigManager.Config.Server.Network.Port}"); listeners[(i * 2) + 1] = new ConnectionListener(hosts[i], ConfigManager.Config.Server.Network.Port + 1); log.Info($"Binding ConnectionListener to {hosts[i]}:{ConfigManager.Config.Server.Network.Port + 1}"); listeners[(i * 2) + 0].Start(); listeners[(i * 2) + 1].Start(); } }
public TimersMap(ConnectionListener <MQMessage> listener, NetworkChannel <MQMessage> client, Int64 resendPeriod, Int64 keepalivePeriod) { this._listener = listener; this._resendPeriod = resendPeriod; this._keepalivePeriod = keepalivePeriod; this._client = client; }
public void registerConnectionListener(ConnectionListenerNotify listener) { ConnectionListener mConnectionListener = new ConnectionListener(); mConnectionListener.setListener(listener); mAIAudio.Call("registerConnectionListener", mConnectionListener); }
internal void AddListener(ConnectionListener listener) { lock (Synchronised) { Listener = listener; } }
public void Clean() { if (ConnectionListener != null) { ConnectionListener.Stop(); } }
public IDisposable Listen(IPEndPoint ep) { if (listening) { throw new InvalidOperationException("Already listening."); } ListenEndPoint = ep; listener = new ConnectionListener(eventBase, ep, 1000); listener.Enable(); listener.ConnectionAccepted = (fd, remoteEp) => { connections++; var ev = new Event(eventBase, fd, Events.EV_WRITE | Events.EV_READ); //if (OnConnection != null) // OnConnection(this, new ConnectionEventArgs(new OarsSocket(ev, remoteEp, this))); }; listening = true; closed = false; // XXX return Disposable(() => Close()); return(null); }
public static ConnectionFactory GetConnectionFactory(ConnectionListener listener) { bool hasFactory = listener.ListenerProperties.TryGet(out VirtualConnectionFactory factory); Debug.Assert(hasFactory); return(factory); }
public async Task ConnectionWriteTest(int port) { if (Environment.GetEnvironmentVariable("APPVEYOR") == "True") { Assert.Inconclusive("Can not test in AppVeyor"); } var message = Encoding.ASCII.GetBytes("HOLA"); using (var connectionListener = new ConnectionListener(port)) { using (var client = new TcpClient()) { connectionListener.Start(); connectionListener.OnConnectionAccepting += (s, e) => { e.Client?.GetStream().Write(message, 0, message.Length); }; await client.ConnectAsync("localhost", port); await Task.Delay(400); var connection = new Connection(client, Encoding.ASCII, "\r\n", true, 0); var response = await connection.ReadTextAsync(); Assert.IsNotNull(response); Assert.AreEqual("HOLA", response); } } }
public WebSocketClientHandler(WSClient client, WebSocketClientHandshaker handshaker, ConnectionListener <MQMessage> listener) { this.client = client; this.handshaker = handshaker; this.listener = listener; this.completionSource = new TaskCompletionSource(); }
/// <summary> /// Runs a client disconnect test on the given listener and connection. /// </summary> /// <param name="listener">The listener to test.</param> /// <param name="connection">The connection to test.</param> internal static void RunClientDisconnectTest(ConnectionListener listener, Connection connection) { ManualResetEvent mutex = new ManualResetEvent(false); ManualResetEvent mutex2 = new ManualResetEvent(false); listener.NewConnection += delegate(object sender, NewConnectionEventArgs args) { args.Connection.Disconnected += delegate(object sender2, DisconnectedEventArgs args2) { mutex2.Set(); }; mutex.Set(); }; listener.Start(); connection.Connect(); mutex.WaitOne(); connection.Close(); mutex2.WaitOne(); }
public async Task OnConnectionFailureTest() { Assert.Ignore("Fix"); const int port = 12348; using (var connectionListener = new ConnectionListener(port)) { using (var client = new TcpClient()) { var isFailure = false; connectionListener.OnConnectionAccepting += (s, e) => { e.Cancel = true; }; connectionListener.OnConnectionFailure += (s, e) => { isFailure = true; }; connectionListener.Start(); await client.ConnectAsync("localhost", port); connectionListener.Stop(); Assert.IsTrue(isFailure); } } }
/// <summary> /// Runs a general test on the given listener and connection. /// </summary> /// <param name="listener">The listener to test.</param> /// <param name="connection">The connection to test.</param> internal static void RunServerToClientTest(ConnectionListener listener, Connection connection, int dataSize, SendOption sendOption) { //Setup meta stuff byte[] data = BuildData(dataSize); ManualResetEvent mutex = new ManualResetEvent(false); //Setup listener listener.NewConnection += delegate(object sender, NewConnectionEventArgs args) { args.Connection.SendBytes(data, sendOption); }; listener.Start(); //Setup conneciton connection.DataReceived += delegate(object sender, DataReceivedEventArgs args) { Trace.WriteLine("Data was received correctly."); for (int i = 0; i < data.Length; i++) { Assert.AreEqual(data[i], args.Bytes[i]); } Assert.AreEqual(sendOption, args.SendOption); mutex.Set(); }; connection.Connect(); //Wait until data is received mutex.WaitOne(); }
/** * Registers an observer to be invoked upon the server's * {@code ConnectionManager} receiving a new connection. * This will not fire if for some internal reason * the connection refuses abruptly.<br /> * <br /> * Returns an id -- that of the listener which is being registered. * This id can be used to remove the listener from operation, if * so desired. * * @param listener The {@code ConnectionListener} implementation to * invoke upon event firing. * @return The ID of the listener. * @see #unregisterConnectionListener(int) */ public int registerConnectionListener(ConnectionListener listener) { if (!this.listeners.Contains(listener)) { this.listeners.Add(listener); } return(this.listeners.IndexOf(listener)); }
public void DisposeListener() { lock (Synchronised) { Listener?.Dispose(); Listener = null; } }
public void CanConnect() { var cw = new ConnectionListener(Mother.CONST_PathToQuik); Assert.IsTrue(cw.Connect()); Assert.IsTrue(cw.IsDllConnected); Assert.IsTrue(cw.IsQuikConnected); Assert.IsTrue(cw.Disconnect()); }
public MainWindow() { ViewModelSession = new ViewModel(); DataContext = ViewModelSession; InitializeComponent(); connectionListener = new ConnectionListener(); connInfoListener = new ConnectionInfoListener(); }
public static void Main(string[] args) { md5 = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")); //System.Diagnostics.Debug.WriteLine ("md5 " + MD5 ("linearch2570" + MD5("4qwh0lyg4n5134"))); dbconn = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString); dbconn.Open(); AddDataHandler(0, Login); AddDataHandler(1, Relog); //2 reserved for register //3 reserved for character creation //4 reserved for logout AddDataHandler(5, RoomList); AddDataHandler(6, CreateRoom); AddDataHandler(7, JoinRoom); AddDataHandler(8, RoomStuff); /*int count = 0; * for (int i = 3000; i < 10000; i++) { * try{ * TcpConnectionListener l = new TcpConnectionListener(IPAddress.Any, i); * l.Start (); * listeners.Add(l); * count++; * }catch(Exception ex){ * Console.WriteLine ("Failed listening on : " + i); * count--; * } * } * Console.WriteLine ("Total listeners : " + count);*/ listener = new TcpConnectionListener(IPAddress.Any, 2570); listener.NewConnection += NewConnectionHandler; listener.Start(); Console.WriteLine("Server started!"); Console.WriteLine("Type 'exit' to exit"); while (true) { string i = Console.ReadLine(); if (i == "exit") { break; } } }
public void Start() { ConnectionListener listener = new ConnectionListener(port); listener.ClientConnected += listener_ClientConnected; listener.ClientDisconnected += listener_ClientDisconnected; listener.ClientMessageReceived += listener_ClientMessageReceived; listener.Start(); }
public void Start() { if (Interlocked.CompareExchange(ref isInActivating, ActiveSentinel, NoneSentinel) != NoneSentinel) { throw new InvalidOperationException("activated"); } connectionListener = binding.CreateConnectionListener(serviceProvider); connectionListener.Start(); }
public override void SetConnectionListeners(List <IConnectionListener> listeners) { base.SetConnectionListeners(listeners); // If the connection is already alive we assume that the new listeners want to be notified if (Connection != null) { ConnectionListener.OnCreate(Connection); } }
public void Stopping_listening_should_not_throw_an_error_if_we_are_not_listening() { // Given var connectionListener = new ConnectionListener(_logger); // When connectionListener.StopListening(); // Then no error should occur }
public SBServerHost(ushort port, string name, bool discoverable) { this.Name = name; if (discoverable) { _discoverer = new DiscoverService(port, name); } _listener = new ConnectionListener(port); _listener.OnNewConnection += NewConnectionHandler; }
private void RegisterBinding(IWampBinding binding, ConnectionListener listener) { if (mBindings.ContainsKey(binding.Name)) { throw new ArgumentException("Already registered a binding for protocol: " + binding.Name, nameof(binding)); } mBindings.Add(binding.Name, listener); }
public void CanSendLimitOrder() { var cw = new ConnectionListener(Mother.CONST_PathToQuik); Assert.IsTrue(cw.Connect()); var tw = new TransactionManager(); var txn = tBuilder.NewOrder(new OrderTradeParams(Mother.SBRF, Direction.Buy, 1, 74.85M)); var res = tw.SendSyncTransaction(txn.ToString()); Console.WriteLine("{0}", res); Assert.IsTrue(res.ReturnValue.IsSuccess); }
public void CanKillStopOrder() { var cw = new ConnectionListener(Mother.CONST_PathToQuik); Assert.IsTrue(cw.Connect()); var tw = new TransactionManager(); var txn = tBuilder.KillStopOrder(Mother.SBRF, "370852"); var res = tw.SendSyncTransaction(txn.ToString()); Console.WriteLine("{0}", res); Assert.IsTrue(res.ReturnValue.IsSuccess); }
public void Start() { initAppwarp (); connListener = new ConnectionListener (); roomListener = new RoomListener (); notify = new NotifyList (); zoneListen = new ZoneListen (); WarpClient.GetInstance ().AddConnectionRequestListener (connListener); WarpClient.GetInstance ().AddRoomRequestListener (roomListener); WarpClient.GetInstance ().AddNotificationListener (notify); WarpClient.GetInstance ().AddZoneRequestListener (zoneListen); }
public void CanConnect() { var cw = new ConnectionListener(Mother.CONST_PathToQuik); Assert.IsTrue(cw.Connect()); Console.WriteLine("Connection result:{0}", cw.LastResult); Assert.IsTrue(cw.IsDllConnected); Assert.IsTrue(cw.IsQuikConnected); Assert.IsTrue(cw.Disconnect()); }
public ConnectionManager(ConnectionListener listener, MessageHandler messageHandler) { if (listener == null) throw new ArgumentNullException(nameof(listener)); if (messageHandler == null) throw new ArgumentNullException(nameof(messageHandler)); _connections = new List<ConnectionModel>(); _listener = listener; _messageHandler = messageHandler; _listener.OnConnectionReceived += OnConnectionReceivedEventHandler; }
internal void addListener(ConnectionListener connectionListener) { _listeners.Add(connectionListener); }
static ConnectionListener() { NULL = new NullConnectionListener(); }
void Start() { warpClient = WarpClient.GetInstance (); // WarpClient.GetInstance() returns null until it is initialized conn_listen = new ConnectionListener(); notify_listen = new NotificationListener(); room_listen = new RoomListener(); }
public override void Stop() { if (_listener != null) { _listener.Shutdown(); _listener = null; } ConnectorFacadeFactory.GetInstance().Dispose(); }
/** * Registers an observer to be invoked upon the server's * {@code ConnectionManager} receiving a new connection. * This will not fire if for some internal reason * the connection refuses abruptly.<br /> * <br /> * Returns an id -- that of the listener which is being registered. * This id can be used to remove the listener from operation, if * so desired. * * @param listener The {@code ConnectionListener} implementation to * invoke upon event firing. * @return The ID of the listener. * @see #unregisterConnectionListener(int) */ public int registerConnectionListener(ConnectionListener listener) { if (!this.listeners.Contains(listener)) { this.listeners.Add(listener); } return this.listeners.IndexOf(listener); }
public override void Stop() { if (_listener != null) { _listener.Shutdown(); _listener = null; } _startDate = 0; ConnectorFacadeFactory.GetManagedInstance().Dispose(); }
public override void Start() { if (IsStarted()) { throw new InvalidOperationException("Server is already running."); } if (Port == 0) { throw new InvalidOperationException("Port must be set prior to starting server."); } if (KeyHash == null) { throw new InvalidOperationException("Key hash must be set prior to starting server."); } if (UseSSL && ServerCertificate == null) { throw new InvalidOperationException("ServerCertificate must be set if using SSL."); } //make sure we are configured properly ConnectorInfoManagerFactory.GetInstance().GetLocalManager(); _requestCount = 0; /* * the Java and .Net dates have a diferent starting point: zero milliseconds in Java corresponds to January 1, 1970, 00:00:00 GMT (aka “the epoch”). * In .Net zero milliseconds* corresponds to 12:00 A.M., January 1, 0001 GMT. * So the basic is to bridge over the reference points gap with adding (or substracting) the corresponding number of milliseconds * such that zero milliseconds in .Net is mapped to -62135769600000L milliseconds in Java. * This number of milliseconds corresponds to GMT zone, so do not forget to include your time zone offset into the calculations. */ _startDate = (DateTime.UtcNow.Ticks - 621355968000000000) / 10000; _pendingRequests.Clear(); TcpListener socket = CreateServerSocket(); ConnectionListener listener = new ConnectionListener(this, socket); listener.Start(); _listener = listener; }
public override void Start() { if (IsStarted()) { throw new InvalidOperationException("Server is already running."); } if (Port == 0) { throw new InvalidOperationException("Port must be set prior to starting server."); } if (KeyHash == null) { throw new InvalidOperationException("Key hash must be set prior to starting server."); } if (UseSSL && ServerCertificate == null) { throw new InvalidOperationException("ServerCertificate must be set if using SSL."); } //make sure we are configured properly ConnectorInfoManagerFactory.GetInstance().GetLocalManager(); _requestCount = 0; _pendingRequests.Clear(); TcpListener socket = CreateServerSocket(); ConnectionListener listener = new ConnectionListener(this, socket); listener.Start(); _listener = listener; }