Penguen
Penguen

Reputation: 17298

How to File Transfer client to Server?

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

alt text 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();
        }

Upvotes: 0

Views: 1531

Answers (3)

Igal Serban
Igal Serban

Reputation: 10684

Maybe you have an active firewall on the machine?

Upvotes: 0

Mohanavel
Mohanavel

Reputation: 1781

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.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039160

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.

Upvotes: 1

Related Questions