public void KeepAliveServerTest() { ManualResetEvent mutex = new ManualResetEvent(false); TcpConnection listenerConnectionToClient = null; using (TcpConnectionListener listener = new TcpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296))) using (TcpConnection connection = new TcpConnection(new NetworkEndPoint(IPAddress.Loopback, 4296))) { listener.NewConnection += delegate(object sender, NewConnectionEventArgs args) { listenerConnectionToClient = (TcpConnection)args.Connection; listenerConnectionToClient.KeepAliveInterval = 100; Thread.Sleep(1050); //Enough time for ~10 keep alive packets mutex.Set(); }; listener.Start(); connection.Connect(); mutex.WaitOne(); Assert.IsNotNull(listenerConnectionToClient); Assert.IsTrue( listenerConnectionToClient.Statistics.TotalBytesSent >= 30 && listenerConnectionToClient.Statistics.TotalBytesSent <= 50, "Sent: " + listenerConnectionToClient.Statistics.TotalBytesSent ); } }
public ClientConnecionService(int port) { var tcpConnectionListener = new TcpConnectionListener(port); tcpConnectionListener.TcpClientConnected += OnClientConnected; tcpConnectionListener.StartAsync(); }
public ActiveEmptySharing() { // Creates a empty share Share share = new Share("Testing"); // Port to listen for incomming connections on share.Port = 12345; AddFilelistsToShare(share); incomingConnectionListener = new TcpConnectionListener(share.Port); incomingConnectionListener.Update += new FmdcEventHandler(Connection_Update); incomingConnectionListener.Start(); HubSetting setting = new HubSetting(); setting.Address = "127.0.0.1"; setting.Port = 411; setting.DisplayName = "FlowLib"; setting.Protocol = "Auto"; Hub hubConnection = new Hub(setting); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); hubConnection.Share = share; hubConnection.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct; hubConnection.Connect(); }
public void TcpClientToServerTest() { using (TcpConnectionListener listener = new TcpConnectionListener(IPAddress.Any, 4296)) using (TcpConnection connection = new TcpConnection(new NetworkEndPoint(IPAddress.Loopback, 4296))) { TestHelper.RunClientToServerTest(listener, connection, 4, 0, SendOption.FragmentedReliable); } }
public void ClientDisconnectTest() { using (TcpConnectionListener listener = new TcpConnectionListener(IPAddress.Any, 4296)) using (TcpConnection connection = new TcpConnection(new NetworkEndPoint(IPAddress.Loopback, 4296))) { TestHelper.RunClientDisconnectTest(listener, connection); } }
public void TcpIPv4ConnectionTest() { using (TcpConnectionListener listener = new TcpConnectionListener(IPAddress.Any, 4296, IPMode.IPv4)) using (TcpConnection connection = new TcpConnection(new NetworkEndPoint(IPAddress.Loopback, 4296, IPMode.IPv4))) { listener.Start(); connection.Connect(); } }
protected virtual void DoUPnPExternalRecieveAccess() { try { tcpListener = new TcpConnectionListener(Port); tcpListener.Update += new FmdcEventHandler(DoUPnPExternalRecieveAccess_Update); tcpListener.Start(); // Don't do this if we don't have external ip if ( (Functions.UPnPDevices & Success) == Functions.UPnPDevices && (Functions.UPnPIGD & Success) == Functions.UPnPIGD && (Functions.UPnPExternalIp & Success) == Functions.UPnPExternalIp && (Functions.UPnPAddMapping & Success) == Functions.UPnPAddMapping && (Functions.UPnPGetMapping & Success) == Functions.UPnPGetMapping && (Functions.UPnPDeleteMapping & Success) == Functions.UPnPDeleteMapping ) { bool hasAddPortMapping = false; if (hasAddPortMapping = wanipService.AddPortMapping(this, mapping)) { //Transfer transfer = new Transfer(ExternalIPUPnP.ToString(), Port); Transfer transfer = new Transfer(ExternalIP.ToString(), Port); UserInfo me = new UserInfo(); me.DisplayName = "upnp"; me.TagInfo.Version = "FlowLibPowered"; transfer.Share = new Share("temp"); transfer.Me = me; transfer.Source = new Source(ExternalIP.ToString(), "upnp"); transferManager.AddTransferReq(new TransferRequest("upnp", null, new UserInfo())); transfer.Protocol = new TransferNmdcProtocol(transfer); transferManager.StartTransfer(transfer); // Wait 60 seconds before continue int i = 0; do { Thread.Sleep(50); } while (((Functions.UPnPExternalRecieveAccess & Success) != Functions.UPnPExternalRecieveAccess) && i++ > 1200); // clean; wanipService.DeletePortMapping(this, mapping); } } tcpListener.Update -= DoUPnPExternalRecieveAccess_Update; tcpListener.End(); tcpListener = null; } finally { Progress = Functions.End; } }
protected virtual void DoInternalListenRecieveAccess() { try { tcpListener = new TcpConnectionListener(Port); tcpListener.Update += new FmdcEventHandler(DoInternalListenAccess_Update); tcpListener.Start(); try { // TODO: We shouldn't limit ourself to IPv4. Transfer transfer = new Transfer("127.0.0.1", Port); UserInfo me = new UserInfo(); me.DisplayName = "loopback"; me.TagInfo.Version = "FlowLibPowered"; transfer.Share = new Share("temp"); transfer.Me = me; // TODO: We shouldn't limit ourself to IPv4. transfer.Source = new Source("127.0.0.1", "loopback"); //transferManager.AddTransferReq(new TransferRequest("loopback", null, new UserInfo())); transferManager.AddTransferReq(new TransferRequest(transfer.Source)); transfer.Protocol = new TransferNmdcProtocol(transfer); transferManager.StartTransfer(transfer); Success |= Functions.InternalListenAccess; } catch { // We do not have InternalListenAccess. Success = Success & ~Functions.InternalListenAccess; } // Wait 10 seconds before continue int i = 0; do { Thread.Sleep(50); } while (((Functions.InternalRecieveAccess & Success) != Functions.InternalRecieveAccess) && i++ > 200); // clean; tcpListener.Update -= DoInternalListenAccess_Update; tcpListener.End(); tcpListener = null; } finally { Progress = Functions.ExternalIp; } }
public void TcpHandshakeTest() { using (TcpConnectionListener listener = new TcpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296, IPMode.IPv4))) using (TcpConnection connection = new TcpConnection(new NetworkEndPoint(IPAddress.Loopback, 4296, IPMode.IPv4))) { listener.Start(); listener.NewConnection += delegate(object sender, NewConnectionEventArgs e) { Assert.IsTrue(Enumerable.SequenceEqual(e.HandshakeData, new byte[] { 1, 2, 3, 4, 5, 6 })); }; connection.Connect(new byte[] { 1, 2, 3, 4, 5, 6 }); } }
protected virtual void DoExternalRecieveAccess() { try { tcpListener = new TcpConnectionListener(Port); tcpListener.Update += new FmdcEventHandler(DoExternalRecieveAccess_Update); tcpListener.Start(); // Don't do this if we don't have external ip if ((Functions.ExternalIp & Success) == Functions.ExternalIp) { Transfer transfer = new Transfer(ExternalIP.ToString(), Port); UserInfo me = new UserInfo(); me.DisplayName = "external"; me.TagInfo.Version = "FlowLibPowered"; transfer.Share = new Share("temp"); transfer.Me = me; transfer.Source = new Source(ExternalIP.ToString(), "external"); transferManager.AddTransferReq(new TransferRequest("external", null, new UserInfo())); transfer.Protocol = new TransferNmdcProtocol(transfer); transferManager.StartTransfer(transfer); } // Wait 30 seconds before continue int i = 0; do { Thread.Sleep(50); } while (((Functions.ExternalRecieveAccess & Success) != Functions.ExternalRecieveAccess) && i++ > 600); // clean; tcpListener.Update -= DoExternalRecieveAccess_Update; tcpListener.End(); tcpListener = null; } finally { if ((Functions.ExternalRecieveAccess & Success) == Functions.ExternalRecieveAccess) { Progress = Functions.End; } else { Progress = Functions.UPnPDevices; } } }
private void InitTcp(int p) { if (_tcpConnectionListener != null) { _tcpConnectionListener.IncomingConnection -= TcpConnectionListenerIncomingConnection; _tcpConnectionListener.Dispose(); _tcpConnectionListener = null; } if (p > 0) { _tcpConnectionListener = new TcpConnectionListener(p, Settings.TcpBacklog); _tcpConnectionListener.IncomingConnection += TcpConnectionListenerIncomingConnection; _tcpConnectionListener.ListenAsync(); } }
public void Run(EventWaitHandle serverStartWaitHandle) { this.World.TickStarted += OnTickStarted; this.World.TickEnded += OnTickEnded; this.World.TurnStarting += OnTurnStarting; this.World.TurnEnded += OnTurnEnded; PipeConnectionListener.StartListening(_OnNewConnection); TcpConnectionListener.StartListening(_OnNewConnection, "SNet"); DirectConnectionListener.StartListening(_OnNewConnection); trace.TraceInformation("The server is ready."); if (serverStartWaitHandle != null) { serverStartWaitHandle.Set(); } CheckForStartTick(); // Enter the main loop m_dispatcher.Run(MainWork); trace.TraceInformation("Server exiting"); DirectConnectionListener.StopListening(); TcpConnectionListener.StopListening(); PipeConnectionListener.StopListening(); this.World.TurnEnded -= OnTurnEnded; this.World.TurnStarting -= OnTurnStarting; this.World.TickEnded -= OnTickEnded; this.World.TickStarted -= OnTickStarted; // Need to disconnect the sockets foreach (var user in m_users) { if (user.IsConnected) { user.Disconnect(); } } trace.TraceInformation("Server exit"); }
public void KeepAliveClientTest() { using (TcpConnectionListener listener = new TcpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296))) using (TcpConnection connection = new TcpConnection(new NetworkEndPoint(IPAddress.Loopback, 4296))) { listener.Start(); connection.Connect(); connection.KeepAliveInterval = 100; System.Threading.Thread.Sleep(1050); //Enough time for ~10 keep alive packets Assert.IsTrue( connection.Statistics.TotalBytesSent >= 30 && connection.Statistics.TotalBytesSent <= 50, "Sent: " + connection.Statistics.TotalBytesSent ); } }
public void TcpFieldTest() { NetworkEndPoint ep = new NetworkEndPoint(IPAddress.Loopback, 4296); using (TcpConnectionListener listener = new TcpConnectionListener(IPAddress.Any, 4296)) using (TcpConnection connection = new TcpConnection(ep)) { listener.Start(); connection.Connect(); //Connection fields Assert.AreEqual(ep, connection.EndPoint); //TcpConnection fields Assert.AreEqual(new IPEndPoint(IPAddress.Loopback, 4296), connection.RemoteEndPoint); Assert.AreEqual(0, connection.Statistics.DataBytesSent); Assert.AreEqual(0, connection.Statistics.DataBytesReceived); } }
static void Main(string[] args) { //Setup listener using (TcpConnectionListener listener = new TcpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296))) { //Start listening for new connection events listener.NewConnection += delegate(object sender, NewConnectionEventArgs a) { //Send the client some data a.Connection.SendBytes(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, SendOption.Reliable); //Disconnect from the client a.Connection.Close(); }; listener.Start(); Console.ReadKey(); } }
void SetListener(uint16_t inPort) { // tcp server listener = new TcpConnectionListener(new NetworkEndPoint(IPAddress.Any, inPort)); //Setup listener listener.NewConnection += delegate(object sender, NewConnectionEventArgs args) { NetIncomingMessage msg1 = GetServer().CreateIncomingMessage(NetIncomingMessageType.TcpStatusChanged, 4 + 1); msg1.isTcp = true; msg1.m_senderEndPoint = ((NetworkEndPoint)(args.Connection).EndPoint).EndPoint as IPEndPoint; msg1.Write((byte)NetConnectionStatus.Connected); msg1.Write(string.Empty); GetServer().ReleaseMessage(msg1); args.Connection.DataReceived += delegate(object innerSender, DataReceivedEventArgs innerArgs) { NetIncomingMessage msg = GetServer().CreateIncomingMessage(NetIncomingMessageType.Data, innerArgs.Bytes.Length); msg.isTcp = true; msg.m_TcpConnecton = (TcpConnection)innerSender; msg.m_senderEndPoint = ((NetworkEndPoint)((Connection)innerSender).EndPoint).EndPoint as IPEndPoint; Buffer.BlockCopy(innerArgs.Bytes, 2, msg.m_data, 0, innerArgs.Bytes.Length - 2); msg.m_bitLength = (ushort)((innerArgs.Bytes[0] << 8) | innerArgs.Bytes[1]); //Log.Information($"TCP recv length {msg.LengthBytes}, session_id {msg.m_TcpConnecton.sessionId}"); GetServer().ReleaseMessage(msg); }; args.Connection.Disconnected += delegate(object sender2, DisconnectedEventArgs args2) { NetIncomingMessage msg = GetServer().CreateIncomingMessage(NetIncomingMessageType.TcpStatusChanged, 4 + 1); msg.isTcp = true; msg.m_senderEndPoint = ((NetworkEndPoint)((Connection)sender2).EndPoint).EndPoint as IPEndPoint; msg.Write((byte)NetConnectionStatus.Disconnected); msg.Write(string.Empty); GetServer().ReleaseMessage(msg); }; }; listener.Start(); }
public MultiConnections() { UpdateBase = new FmdcEventHandler(PassiveConnectToUser_UpdateBase); // Creates a empty share Share share = new Share("Testing"); // Port to listen for incomming connections on share.Port = 12345; incomingConnectionListener = new TcpConnectionListener(share.Port); incomingConnectionListener.Update += new FmdcEventHandler(Connection_Update); incomingConnectionListener.Start(); // Adds common filelist to share AddFilelistsToShare(share); HubSetting setting = new HubSetting(); setting.Address = "127.0.0.1"; setting.Port = 411; setting.DisplayName = "FlowLib"; setting.Protocol = "Auto"; hub = new Hub(setting, this); hub.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); // Adds share to hub hub.Share = share; hub.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct; hub.Connect(); last = System.DateTime.Now.Ticks; timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.AutoReset = true; timer.Interval = 1000; timer.Start(); }
public void Start() { NetworkEndPoint endPoint = new NetworkEndPoint(IPAddress.Any, portNumber); ConnectionListener listener = new TcpConnectionListener(endPoint); Running = true; Console.WriteLine("Starting server!"); Console.WriteLine("Server listening on " + (listener as TcpConnectionListener).EndPoint); listener.NewConnection += NewConnectionHandler; listener.Start(); while (Running) { //Do nothing } //Close all listener.Close(); //Exit 0 Environment.Exit(0); }
public ActiveEmptySharingUsingTLS() { // Creates a empty share Share share = new Share("Testing"); // Port to listen for incomming connections on share.Port = 12345; AddFilelistsToShare(share); incomingConnectionListener = new TcpConnectionListener(share.Port); incomingConnectionListener.Update += new FmdcEventHandler(Connection_Update); incomingConnectionListener.Start(); // TLS listener incomingConnectionListenerTLS = new TcpConnectionListener(tlsport); incomingConnectionListenerTLS.Update += new FmdcEventHandler(Connection_UpdateTLS); incomingConnectionListenerTLS.Start(); HubSetting setting = new HubSetting(); setting.Address = "127.0.0.1"; setting.Port = 411; setting.DisplayName = "FlowLibActiveTLS"; setting.Protocol = "Auto"; Hub hubConnection = new Hub(setting); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); hubConnection.Share = share; hubConnection.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct; #if !COMPACT_FRAMEWORK // Security, Windows Mobile doesnt support SSLStream so we disable this feature for it. hubConnection.Me.Set(UserInfo.SECURE, tlsport.ToString()); #endif hubConnection.Connect(); }
public void InitSinglePlayerServer(WorldParameters worldParam) { if (Server != null) { throw new InvalidOperationException("Already initialized"); } _worldParam = worldParam; _serverFactory = new EntityFactory(); _serverFactory.Config = _worldParam.Configuration; var dbPath = Path.Combine(_vars.ApplicationDataPath, "Server", "Singleplayer", worldParam.WorldName, "ServerWorld.db"); logger.Info("Local world db path is {0}", dbPath); _serverSqliteStorageSinglePlayer = new SqliteStorageManager(dbPath, _serverFactory, worldParam); _serverSqliteStorageSinglePlayer.Register("local", "qwe123".GetSHA1Hash(), UserRole.Administrator); var settings = new XmlSettingsManager <ServerSettings>(@"Server\localServer.config"); settings.Load(); settings.Save(); //Utopia New Landscape Test IWorldProcessor processor = null; IEntitySpawningControler entitySpawningControler = null; switch (worldParam.Configuration.WorldProcessor) { case WorldConfiguration.WorldProcessors.Flat: processor = new FlatWorldProcessor(); break; case WorldConfiguration.WorldProcessors.Utopia: processor = new UtopiaProcessor(worldParam, _serverFactory, _landscapeEntityManager); entitySpawningControler = new UtopiaEntitySpawningControler((UtopiaWorldConfiguration)worldParam.Configuration); break; default: break; } var worldGenerator = new WorldGenerator(worldParam, processor); worldGenerator.EntitySpawningControler = entitySpawningControler; //Old s33m3 landscape //IWorldProcessor processor1 = new s33m3WorldProcessor(worldParam); //IWorldProcessor processor2 = new LandscapeLayersProcessor(worldParam, _serverFactory); //var worldGenerator = new WorldGenerator(worldParam, processor1, processor2); //Vlad Generator //var planProcessor = new PlanWorldProcessor(wp, _serverFactory); //var worldGenerator = new WorldGenerator(wp, planProcessor); settings.Settings.ChunksCountLimit = 1024 * 3; // better use viewRange * viewRange * 3 var port = 4815; while (!TcpConnectionListener.IsPortFree(port)) { port++; } settings.Settings.ServerPort = port; _server = new ServerCore(settings, worldGenerator, _serverSqliteStorageSinglePlayer, _serverSqliteStorageSinglePlayer, _serverSqliteStorageSinglePlayer, _serverSqliteStorageSinglePlayer, _serverFactory, worldParam); _serverFactory.LandscapeManager = Server.LandscapeManager; _serverFactory.DynamicEntityManager = Server.AreaManager; _serverFactory.GlobalStateManager = Server.GlobalStateManager; _serverFactory.ScheduleManager = Server.Scheduler; _serverFactory.ServerSide = true; _server.Initialize(); Server.ConnectionManager.LocalMode = true; Server.ConnectionManager.Listen(); Server.LoginManager.PlayerEntityNeeded += LoginManagerPlayerEntityNeeded; Server.LoginManager.GenerationParameters = default(Utopia.Shared.World.PlanGenerator.GenerationParameters); // planProcessor.WorldPlan.Parameters; Server.Clock.SetCurrentTimeOfDay(UtopiaTimeSpan.FromHours(12)); }
public ConnectionManager(int portToListen) : this() { Listener = new TcpConnectionListener(portToListen); Listener.IncomingConnection += ListenerIncomingConnection; }
public DcEngine(EngineSettings settings) { Settings = settings; Settings.Changed += SettingsChanged; TagInfo = new TagInfo(); Hubs = new HubCollection(); Hubs.HubAdded += HubsHubAdded; Hubs.HubRemoved += HubsHubRemoved; SearchManager = new SearchManager(this); DownloadManager = new DownloadManager(this); DownloadManager.DownloadAdding += DownloadManagerDownloadAdding; DownloadManager.DownloadCompleted += DownloadManager_DownloadCompleted; TransferManager = new TransferManager(this); TransferManager.TransferAdded += TransferManagerTransferAdded; TransferManager.TransferRemoved += TransferManagerTransferRemoved; TransferManager.TransferUploadItemError += TransferManagerTransferUploadItemError; TransferManager.TransferUploadItemRequest += TransferManager_TransferUploadItemRequest; SourceManager = new SourceManager(); FileSourceManager = new FileSourceManager(); StatisticsManager = new StatisticsManager(this); UploadCacheManager = new UploadCacheManager(this); if (Settings.AutoSelectPort) { var tcpPort = Settings.TcpPort; var udpPort = Settings.UdpPort; while (!TcpConnectionListener.IsPortFree(tcpPort)) { tcpPort++; } if (Settings.TcpPort != tcpPort) { Settings.TcpPort = tcpPort; } else { InitTcp(Settings.TcpPort); } while (!UdpConnection.IsPortFree(udpPort)) { udpPort++; } if (Settings.UdpPort != udpPort) { Settings.UdpPort = udpPort; } else { InitUdp(Settings.UdpPort); } } else { InitUdp(Settings.UdpPort); InitTcp(Settings.TcpPort); } if (string.IsNullOrEmpty(Settings.LocalAddress)) { // find local ip var host = Dns.GetHostEntry(Dns.GetHostName()); //Array.Sort(host.AddressList, (one, two) => (one.ToString().StartsWith("192.168")?1:0)+ (two.ToString().StartsWith("192.168")?-1:0)); foreach (var ip in host.AddressList) { if (ip.AddressFamily.ToString() == "InterNetwork") { Settings.LocalAddress = ip.ToString(); break; } } } if (Settings.HttpQueueLimit != 0) { HttpUploadItem.Manager.QueueLimit = Settings.HttpQueueLimit; } if (Settings.HttpConnectionsPerServer != 0) { HttpUploadItem.Manager.ConnectionsPerServer = Settings.HttpConnectionsPerServer; } }
/// <summary> /// Initializes the service, implementing classes have to invoke one way or another /// </summary> protected ServiceHost() { listener = new TcpConnectionListener(11143); //TODO configurable }
internal AccountConnectionManager(PongServerApplication application) { this.application = application; tcpListener = new TcpConnectionListener(IPAddress.Any, 8080); tcpListener.IncomingConnection += OnIncomingConnection; }
public void Initialize() { string downloadsPath = Client.Settings.StorageAutoSelect ? StorageHelper.GetBestSaveDirectory() : Client.Settings.StoragePath; if (Client.Settings.TorrentTcpPort == 0) { var r = new Random(); int port; while (!TcpConnectionListener.IsPortFree(port = r.Next(6881, 7000))) { } logger.Info("Auto selected torrent port: {0}", port); Client.Settings.TorrentTcpPort = port; } var engineSettings = new EngineSettings(downloadsPath, Client.Settings.TorrentTcpPort) { PreferEncryption = false, AllowedEncryption = EncryptionTypes.All }; _torrentDefaults = new TorrentSettings(4, 50, 0, 0); _engine = new ClientEngine(engineSettings); _engine.ChangeListenEndpoint(new IPEndPoint(IPAddress.Any, Client.Settings.TorrentTcpPort)); byte[] nodes = null; try { nodes = File.ReadAllBytes(TorrentDhtNodesPath); } catch { logger.Info("No existing dht nodes could be loaded"); } var dhtListner = new DhtListener(new IPEndPoint(IPAddress.Any, Client.Settings.TorrentTcpPort)); var dht = new DhtEngine(dhtListner); _engine.RegisterDht(dht); dhtListner.Start(); _engine.DhtEngine.Start(nodes); // If the SavePath does not exist, we want to create it. if (!Directory.Exists(_engine.Settings.SavePath)) { Directory.CreateDirectory(_engine.Settings.SavePath); } // If the torrentsPath does not exist, we want to create it if (!Directory.Exists(TorrentsFolder)) { Directory.CreateDirectory(TorrentsFolder); } BEncodedDictionary fastResume; try { if (File.Exists(TorrentFastResumePath)) { fastResume = BEncodedValue.Decode <BEncodedDictionary>(File.ReadAllBytes(TorrentFastResumePath)); } else { fastResume = new BEncodedDictionary(); } } catch { fastResume = new BEncodedDictionary(); } var knownTorrentsPaths = Directory.GetFiles(TorrentsFolder, "*.torrent"); logger.Info("Loading {0} saved torrents", knownTorrentsPaths.Length); foreach (var file in knownTorrentsPaths) { Torrent torrent; try { torrent = Torrent.Load(file); } catch (Exception e) { logger.Error("Couldn't decode {0}: ", file); logger.Error(e.Message); continue; } var manager = new TorrentManager(torrent, downloadsPath, TorrentDefaults); if (fastResume.ContainsKey(torrent.InfoHash.ToHex())) { manager.LoadFastResume(new FastResume((BEncodedDictionary)fastResume[torrent.InfoHash.ToHex()])); } RegisterTorrent(manager); manager.Start(); } #if DEBUG FrmDebug = new FrmDownloadDebug(); FrmDebug.Width = Screen.PrimaryScreen.WorkingArea.Width; FrmDebug.Show(); #endif }
/// <summary> /// Creates a new TcpConnectionListener on the specified port. /// </summary> /// <param name="port">The port to listen for new connections on.</param> /// <returns>An implementation of IConnectionListener.</returns> public static IConnectionListener CreateTcpConnectionListener(int port) { TcpConnectionListener listener = new TcpConnectionListener(port); return(listener); }
public DcBot(HubSetting settings) { UpdateBase = new FlowLib.Events.FmdcEventHandler(DcBot_UpdateBase); downloadManager.DownloadCompleted += new FmdcEventHandler(downloadManager_DownloadCompleted); // Creates a empty share Share share = new Share("Testing"); // Do we want bot to be active? if (Program.USE_ACTIVE_MODE) { if (Program.PORT_TLS > 0) { share.Port = Program.PORT_TLS; } else { share.Port = Program.PORT_ACTIVE; } incomingConnectionListener = new TcpConnectionListener(Program.PORT_ACTIVE); incomingConnectionListener.Update += new FmdcEventHandler(Connection_Update); incomingConnectionListener.Start(); // TLS listener incomingConnectionListenerTLS = new TcpConnectionListener(Program.PORT_TLS); incomingConnectionListenerTLS.Update += new FmdcEventHandler(Connection_UpdateTLS); incomingConnectionListenerTLS.Start(); } // Adds common filelist to share AddFilelistsToShare(share); hubConnection = new Hub(settings, this); hubConnection.Me.TagInfo.Version = "Serie V:20101125"; hubConnection.Me.TagInfo.Slots = 2; // DO NOT CHANGE THIS LINE! hubConnection.Me.Set(UserInfo.PID, "7OP7K374IKV7YMEYUI5F5R4YICFT36M7FL64AWY"); // Adds share to hub hubConnection.Share = share; // Do we want bot to be active? if (Program.USE_ACTIVE_MODE) { hubConnection.Me.TagInfo.Mode = FlowLib.Enums.ConnectionTypes.Direct; hubConnection.Me.Set(UserInfo.SECURE, Program.PORT_TLS.ToString()); } else { hubConnection.Me.TagInfo.Mode = FlowLib.Enums.ConnectionTypes.Passive; hubConnection.Me.Set(UserInfo.SECURE, ""); } hubConnection.ConnectionStatusChange += new FmdcEventHandler(hubConnection_ConnectionStatusChange); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); hubConnection.SecureUpdate += new FmdcEventHandler(hubConnection_SecureUpdate); }
public CollectTransferedInformationFromFilelistDownload() { UpdateBase = new FmdcEventHandler(PassiveConnectToUser_UpdateBase); // Creates a empty share Share share = new Share("Testing"); // Port to listen for incomming connections on share.Port = 12345; incomingConnectionListener = new TcpConnectionListener(share.Port); incomingConnectionListener.Update += new FmdcEventHandler(Connection_Update); incomingConnectionListener.Start(); // Adds common filelist to share AddFilelistsToShare(share); HubSetting setting = new HubSetting(); setting.Address = "127.0.0.1"; setting.Port = 411; setting.DisplayName = "FlowLib"; setting.Protocol = "Auto"; Hub hubConnection = new Hub(setting, this); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); // Adds share to hub hubConnection.Share = share; //hubConnection.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct; hubConnection.Me.TagInfo.Slots = 2; hubConnection.Connect(); FlowLib.Utils.Convert.General.BinaryPrefixes bp; Console.WriteLine("Press any key to update information"); do { Console.ReadKey(true); Console.Clear(); Console.WriteLine("Press any key to update information"); Console.WriteLine("=================================="); if (stats != null) { Console.WriteLine("Total data sent: " + FlowLib.Utils.Convert.General.FormatBytes(stats.TotalBytesSent, out bp) + bp); Console.WriteLine("Total data received: " + FlowLib.Utils.Convert.General.FormatBytes(stats.TotalBytesReceived, out bp) + bp); Console.WriteLine("current download speed: " + FlowLib.Utils.Convert.General.FormatBytes(stats.CurrentReceiveSpeed, out bp) + bp + "/s"); Console.WriteLine("current upload speed: " + FlowLib.Utils.Convert.General.FormatBytes(stats.CurrentSendSpeed, out bp) + bp + "/s"); Decimal d = new decimal(stats.MaximumReceiveSpeed); Console.WriteLine("Maximum download speed: " + FlowLib.Utils.Convert.General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); d = new decimal(stats.MaximumSendSpeed); Console.WriteLine("Maximum upload speed: " + FlowLib.Utils.Convert.General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); d = new decimal(stats.MinimumReceiveSpeed); Console.WriteLine("Minimum download speed: " + FlowLib.Utils.Convert.General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); d = new decimal(stats.MinimumSendSpeed); Console.WriteLine("Minimum upload speed: " + FlowLib.Utils.Convert.General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); } else { Console.WriteLine("No transfer has started yet."); } Console.WriteLine("=================================="); } while (true); }