Пример #1
0
        // Initialise the program to a known state
        // defaults to a client

        public TorrentMainForm()
        {
            InitializeComponent();
            this.manager = new ConnManager(11000, false);

            // Open the Id form to gather an id from the user
            using (IdForm idForm = new IdForm())
            {
                idForm.StartPosition = FormStartPosition.CenterParent;
                idForm.ShowDialog(this);

                id = idForm.GetID();
            }

            if (string.IsNullOrWhiteSpace(id))
            {
                this.Close();
            }
            peerConnectedList = new List <UIPeer>();
            uIUpdater         = new UIUpdater(dataGridView1, dataGridViewConnectedPeers, dataGridViewLatestTorrent);
        }
Пример #2
0
        public Connection(Socket sock, ConnManager manager, Func <Connection, int> processingFunction, TorrentFile inTorrentFile, int inPort, bool didConnect)
        {
            _state = new ConnectionState();

            // Set a timeout on the socket, as communication should be constant
            sock.ReceiveTimeout = 10000;
            sock.SendTimeout    = 10000;

            _state.sock = sock;

            g = Guid.NewGuid();

            IPEndPoint remoteIpEndPoint = sock.RemoteEndPoint as IPEndPoint;

            ipAddress = remoteIpEndPoint.Address.ToString();

            _manager = manager;

            _reader = new Reader(_state);
            _writer = new Writer(_state);

            // Set the port and torrent file
            port        = inPort;
            torrentFile = inTorrentFile;

            Console.WriteLine("CONNECTION CREATED!");
            peer = new Peer("", port, didConnect, torrentFile, this);

            if (processingFunction != null)
            {
                this.processingFunction = processingFunction;
            }
            else
            {
                this.processingFunction = this.defaultProcessing;
            }
        }
Пример #3
0
 public Listener(ConnManager parent, int port)
 {
     manager   = parent;
     this.port = port;
 }