首页 新闻 会员 周边 捐助

sBinarySocket.Send(br.ReadBytes(1024 * 1024 * 5));这句话有什么问题吗?

0
悬赏园豆:5 [已解决问题] 解决于 2016-08-12 19:58
   /// <summary>
        /// 向用户发送下载的文件
        /// </summary>
        /// <param name="sSocket"></param>
        /// <param name="Parameter"></param>
        /// <param name="si"></param>
        public void ProcessRetreiveCommand(Socket sSocket, string Parameter, SessionInfo si)
        {
            try
            {
                if (File.Exists(si.szFtpRoot + @"\" + Parameter))
                {
                    //文件
                    using (FileStream pStream = new FileStream(si.szFtpRoot + @"\" + Parameter, FileMode.Open))
                    {
                        if (si.fBinary)
                        {
                            //Reply(sSocket, 150, "Opening BINARY mode data connection for '" + Parameter + "'");
                            using (BinaryReader br = new BinaryReader(pStream))
                            {
                                Socket sBinarySocket;
                                if (si.fPassive)
                                {
                                    sBinarySocket = si.pi.tcpListener.AcceptSocket();
                                }
                                else
                                {
                                    sBinarySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                                    sBinarySocket.Bind(localEP);
                                    sBinarySocket.Connect(remoteEP);
                                }
                                while (br.BaseStream.Position < br.BaseStream.Length)
                                {
                                    sBinarySocket.Send(br.ReadBytes(1024 * 1024 * 5));
                                }
                                sBinarySocket.Close();
                            }
                        }
                        else
                        {
                            //Reply(sSocket, 150, "Opening ASCII mode data connection for '" + Parameter + "'");
                            using (StreamReader sr = new StreamReader(pStream))
                            {
                                if (si.fPassive)
                                {
                                    SendOverPassiveDataConnection(GetBytes(sr.ReadToEnd()), si);
                                }
                                else
                                {
                                    SendOverDataConnection(GetBytes(sr.ReadToEnd()));
                                }
                            }
                        }
                        Reply(sSocket, 200, "Transfer Complete");
                    }
                }
            }

为什么 sBinarySocket.Close();有时不被执行,直接跳出了。

~冰的主页 ~冰 | 小虾三级 | 园豆:509
提问于:2015-08-24 19:36
< >
分享
最佳答案
0

br.ReadBytes(1024 * 1024 * 5)是读多大的内容吧,sBinarySocket.Close()你自己去调试下吧

收获园豆:5
稳稳的河 | 老鸟四级 |园豆:4216 | 2015-08-24 20:00
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册