How to File Transfer client to Server?
Posted
by Phsika
on Stack Overflow
See other posts from Stack Overflow
or by Phsika
Published on 2010-05-07T09:56:39Z
Indexed on
2010/06/14
3:02 UTC
Read the original article
Hit count: 356
i try to recieve a file from server but give me error on server.Start()
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();
}
© Stack Overflow or respective owner