开发者

How to File Transfer client to Server?

i try to recieve a file from server but give me error on server.Start()

How to File Transfer client to Server?

ERROR : In a manner not permitted by the access permissions to access a socket was attempted to How can i solve it?

  private void btn_Recieve_Click(object sender, EventArgs e)
        {
            TcpListener server = null开发者_开发百科;
            // Set the TcpListener on port 13000.
            Int32 port = 13000;
            IPAddress localAddr = IPAddress.Parse("192.168.1.201");
            // TcpListener server = new TcpListener(port);
            server = new TcpListener(localAddr, port);
            // Start listening for client requests.

            server.Start();
            // Buffer for reading data
            Byte[] bytes = new Byte[277577];
            String data;
            data = null;
            // Perform a blocking call to accept requests.
            // You could also user server.AcceptSocket() here.
            TcpClient client = server.AcceptTcpClient();
            NetworkStream stream = client.GetStream();
            int i;
            i = stream.Read(bytes, 0, 277577);
            BinaryWriter writer = new BinaryWriter(File.Open("GoodLuckToMe.jpg", FileMode.Create));
            writer.Write(bytes);
            writer.Close();
            client.Close();
        }


Try specifying a local address:

IPAddress localAddr = IPAddress.Loopback;

And make sure that the account your application is running under has sufficient privileges to open ports on the computer.


I couldn't read the exception, try change the different PORT number and check once. If the port is accessed by other process, you may get exception. I hope this is because of port.


Maybe you have an active firewall on the machine?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜