Ejemplo n.º 1
0
        static internal void Run(Udt.Socket conn, string file, bool bVerbose)
        {
            int ini = Environment.TickCount;

            using (Udt.NetworkStream netStream = new Udt.NetworkStream(conn))
                using (BinaryWriter writer = new BinaryWriter(netStream))
                    using (BinaryReader reader = new BinaryReader(netStream))
                        using (FileStream fileReader = new FileStream(file, FileMode.Open, FileAccess.Read))
                        {
                            long fileSize = new FileInfo(file).Length;

                            writer.Write(Path.GetFileName(file));
                            writer.Write(fileSize);

                            byte[] buffer = new byte[512 * 1024];

                            long pos = 0;

                            int i = 0;

                            ConsoleProgress.Draw(i++, pos, fileSize, ini, Console.WindowWidth / 3);

                            while (pos < fileSize)
                            {
                                int toSend = buffer.Length < (fileSize - pos)
                        ? buffer.Length
                        : (int)(fileSize - pos);

                                fileReader.Read(buffer, 0, toSend);

                                int iteration = Environment.TickCount;

                                writer.Write(toSend);
                                conn.Send(buffer, 0, toSend);

                                if (!reader.ReadBoolean())
                                {
                                    Console.WriteLine("Error in transmission");
                                    return;
                                }

                                pos += toSend;

                                ConsoleProgress.Draw(i++, pos, fileSize, ini, Console.WindowWidth / 3);

                                if (bVerbose)
                                {
                                    Console.WriteLine();

                                    Console.WriteLine("Current: {0} / s",
                                                      SizeConverter.ConvertToSizeString(toSend / (Environment.TickCount - iteration) * 1000));

                                    Console.WriteLine("BandwidthMbps {0} mbps.", conn.GetPerformanceInfo().Probe.BandwidthMbps);
                                    Console.WriteLine("RoundtripTime {0}.", conn.GetPerformanceInfo().Probe.RoundtripTime);
                                    Console.WriteLine("SendMbps {0}.", conn.GetPerformanceInfo().Local.SendMbps);
                                    Console.WriteLine("ReceiveMbps {0}.", conn.GetPerformanceInfo().Local.ReceiveMbps);
                                }
                            }
                        }
        }
Ejemplo n.º 2
0
        static int Main(string[] args)
        {
            if ((1 < args.Length) || ((1 == args.Length) && (0 == int.Parse(args[0]))))
            {
                Console.WriteLine("Usage: SendFile [ServerPort]");
                return(1);
            }

            try
            {
                using (Udt.Socket server = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
                {
                    int port = 9000;
                    if (1 == args.Length)
                    {
                        port = int.Parse(args[0]);
                    }

                    server.Bind(IPAddress.Any, port);
                    Console.WriteLine("Server is ready at port: {0}", port);
                    server.Listen(1);

                    using (Udt.Socket client = server.Accept())
                    {
                        server.Close();

                        // Receive file name from client
                        byte[] file = new byte[1024];
                        int    length;
                        string name;

                        client.Receive(file, 0, sizeof(int));
                        length = BitConverter.ToInt32(file, 0);

                        client.Receive(file, 0, length);
                        name = Encoding.UTF8.GetString(file, 0, length);

                        // Send file size information
                        client.Send(BitConverter.GetBytes(new FileInfo(name).Length), 0, sizeof(long));

                        Udt.TraceInfo trace = client.GetPerformanceInfo();

                        // Send the file
                        client.SendFile(name);

                        trace = client.GetPerformanceInfo();

                        PrintProps("Total", trace.Total);
                        PrintProps("Local", trace.Local);
                        PrintProps("Probe", trace.Probe);

                        client.Close();
                    }
                }

                Console.ReadKey(true);
                return(0);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error sending file: {0}", ex.Message);
                Console.ReadKey(true);
                return(2);
            }
        }
Ejemplo n.º 3
0
 public void GetPerformanceInfo__NotConnected()
 {
     using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
     {
         Udt.SocketException error = Assert.Throws <Udt.SocketException>(() => socket.GetPerformanceInfo());
         Assert.AreEqual(Udt.SocketError.NoConnection, error.SocketErrorCode);
     }
 }
Ejemplo n.º 4
0
 public void GetPerformanceInfo__NotConnected()
 {
     using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream))
     {
         Udt.SocketException error = Assert.Throws<Udt.SocketException>(() => socket.GetPerformanceInfo());
         Assert.AreEqual(Udt.SocketError.NoConnection, error.SocketErrorCode);
     }
 }