Exemple #1
0
        public void Start()
        {
            Task.Factory.StartNew(() =>
            {
                Configure();
                try
                {
                    UDTReceiver.connectionExpiryDisabled = true;

                    UDTServerSocket server = new UDTServerSocket(serverPort, localIP);
                    while (true)
                    {
                        UDTSocket socket = server.Accept();
                        Thread.Sleep(1000);

                        Task.Factory.StartNew(() =>
                        {
                            new RequestRunner(socket).Run();
                        });
                    }
                }
                catch (Exception ex)
                {
                    // throw new RuntimeException(ex);
                }
            });
        }
Exemple #2
0
 /**
  *
  * @param localIP 本地IP
  * @param port  端口
  */
 public judpServer(string localIP, int port)
 {
     try {
         server = new UDTServerSocket(port, localIP);
     } catch (SocketException e) {
         FlashLogger.Warn("绑定失败:" + e.Message);
         isSucess = false;
     } catch (Exception e) {
         isSucess = false;
         Console.WriteLine(e);
     }
 }
Exemple #3
0
        static void Main(string[] args)
        {
            UDTServerSocket socket   = new UDTServerSocket(7777, "127.0.0.1");
            UDTSocket       dTSocket = socket.Accept();

            byte[] buffer = new byte[1470];
            while (!dTSocket.IsClose())
            {
                int r = dTSocket.GetInputStream().Read(buffer);
                Console.WriteLine(Encoding.Default.GetString(buffer, 0, r));
            }
        }
Exemple #4
0
        public void Run()
        {
            try
            {
                //create an UDTServerSocket on a free port
                UDTServerSocket server = new UDTServerSocket(0);
                // do hole punching to allow the client to connect
                IPAddress  clientAddress = IPAddress.Parse(clientIP);
                IPEndPoint point         = new IPEndPoint(clientAddress, clientPort);
                //发送一字节确认端口
                Util.DoHolePunch(server.getEndpoint(), point);
                int localPort = server.getEndpoint().LocalPort; //获取真实端口
                                                                //output client port
                writeToOut("OUT: " + localPort);

                //now start the send...
                UDTSocket       socket    = server.Accept();
                UDTOutputStream outStream = socket.GetOutputStream();
                FileInfo        file      = new FileInfo(localFilename);
                if (!file.Exists)
                {
                    Console.WriteLine("没有文件:" + localFilename);
                    socket.Close();
                    server.ShutDown();
                    return;
                }
                FileStream fis = new FileStream(localFilename, FileMode.Open);
                try
                {
                    //send file size info
                    long size = fis.Length;
                    PacketUtil.Encode(size);
                    outStream.Write(PacketUtil.Encode(size));
                    long start = DateTime.Now.Ticks;
                    //and send the file
                    Util.CopyFileSender(fis, outStream, size, false);
                    long end = DateTime.Now.Ticks;
                    Console.WriteLine(socket.GetSession().Statistics);
                    float mbRate   = 1000 * size / 1024 / 1024 / (end - start);
                    float mbitRate = 8 * mbRate;
                    Console.WriteLine("Rate: " + (int)mbRate + " MBytes/sec. " + mbitRate + " mbit/sec.");
                }
                finally
                {
                    fis.Close();
                    socket.Close();
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #5
0
 /**
  *
  * @param port 端口
  */
 public judpServer(int port)
 {
     try {
         server = new UDTServerSocket(port);
     } catch (SocketException e) {
         // logger.log(Level.WARNING, "绑定失败:" + e.getMessage());
         FlashLogger.Warn("绑定失败:" + e.Message);
         isSucess = false;
     } catch (Exception e) {
         isSucess = false;
         Console.WriteLine(e);
     }
 }
Exemple #6
0
        public void RunSend()
        {
            try
            {
                UDTReceiver.connectionExpiryDisabled = true;
                //IPAddress myHost = null;
                //if (localIP != "")
                //{
                //    myHost = IPAddress.Parse(localIP);
                //}
                //else
                //{
                //    string hostname = Dns.GetHostName();
                //    IPHostEntry hostip = Dns.GetHostEntry(hostname);
                //    foreach (IPAddress ipaddress in hostip.AddressList)
                //    {
                //        if (ipaddress.ToString().IndexOf(':') < 0)//存在IPV6的地址,所以要判断
                //        {
                //            myHost = ipaddress;
                //            break;
                //        }
                //    }
                //}

                UDTServerSocket server = new UDTServerSocket(serverPort);
                ThreadPool.SetMaxThreads(1, 1);

                while (true)
                {
                    //启动监听(第一次),及获取已经存在的连接信息
                    UDTSocket socket = server.Accept();
                    Thread.Sleep(1000);
                    TaskInfo ti = new TaskInfo(socket, verbose);

                    ThreadPool.QueueUserWorkItem(new WaitCallback(run), ti);
                }
            }
            catch (Exception ex)
            {
                Log.Write(this.ToString(), ex);
            }
        }