private void Set_couple(
            Int32 senderPort,
            Int32 receiverPort,
            Action <Object, PacketContext> func)
        {
            var senderInfo   = new IPEndPoint(SocketHelper.GetIPAddress(), senderPort);
            var receiverInfo = new IPEndPoint(SocketHelper.GetIPAddress(), receiverPort);

            this.Receiver = new TcpPacketsReceiver(receiverInfo, 2);
            this.Sender   = new TcpSender(senderInfo, receiverInfo);

            this.Receiver.Listen();
            this.Sender.Connect();

            this.Receiver.ReceivedData += ((o, e) => func(o, e));
        }
Ejemplo n.º 2
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            try
            {
                var serverIp   = SocketHelper.GetIPAddress();
                var serverPort = Convert.ToInt32(this.View.configurationPanel1.textBox2.Text);
                var count      = Convert.ToInt32(this.View.configurationPanel1.textBox3.Text);

                var serverService = Provider.GetService <ServerService>();
                serverService.Setup(new System.Net.IPEndPoint(serverIp, serverPort));
                this.SetConnected(true);
            }
            catch (Exception error)
            {
                var form = new ErrorDialogBox(error.Message);
                form.ShowDialog();
                return;
            }
        }
        public void Send_a_file()
        {
            var target      = @"C:\Users\Freddy\Desktop\Sandbox\bestPractices.txt";
            var file        = File.ReadAllBytes(target);
            var destination = @"C:\Users\Freddy\Desktop\Sandbox\Destination\bestPractices.txt";

            var senderInfo   = new IPEndPoint(SocketHelper.GetIPAddress(), 8781);
            var receiverInfo = new IPEndPoint(SocketHelper.GetIPAddress(), 8782);

            this.Receiver = new TcpPacketsReceiver(receiverInfo, 2);
            this.Sender   = new TcpSender(senderInfo, receiverInfo);

            var packetDispatcher = new PacketDispatcher(this.Receiver,
                                                        new List <Handler.IPacketHandler>
            {
                new DirectoryRequestHandler()
            });

            packetDispatcher.Start();

            this.Sender.Connect();

            var namePacktes = PacketHelper.Frame(HeaderContainer.FileName, Encoding.ASCII.GetBytes(destination));

            this.Sender.Send(namePacktes);


            var filePacktes = PacketHelper.Frame(HeaderContainer.FileContent, file);

            this.Sender.Send(filePacktes);


            var packets = PacketHelper.Frame(HeaderContainer.EndFileContent, new Byte[] { 0x22 });

            this.Sender.Send(packets);


            Assert.AreEqual(file, File.ReadAllBytes(destination));

            this.Receiver.Close();
            this.Sender.Close();
        }
Ejemplo n.º 4
0
        private void Connect(object sender, EventArgs e)
        {
            try
            {
                var clientIp   = SocketHelper.GetIPAddress();
                var clientPort = Convert.ToInt32(this.View.connectionPanel1.portTextBox.Text);

                var serverIp   = SocketHelper.GetIPAddress();
                var serverPort = Convert.ToInt32(this.View.connectionPanel1.serverPortTextbox.Text);


                this.Handler.Setup(
                    new IPEndPoint(clientIp, clientPort),
                    new IPEndPoint(serverIp, serverPort));

                this.SetConnected(true);
            }
            catch (Exception excep)
            {
                var form = new ErrorDialogBox(excep.Message);
                form.ShowDialog();
                return;
            }
        }