views:

68

answers:

3

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();
        }
A: 

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.

Darin Dimitrov
"No error is the same as before" -- same error as before
Mohanavel
Error the same as before...
Phsika
A: 

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.

Mohanavel
A: 

Maybe you have an active firewall on the machine?

Igal Serban