hello everyone,
I have created a console app for receiving files thru sockets.
Now what i need to do is to change it to a windows service so that it will dynamically keep receiving files all the times -- and store them in a separate folder.
The problem is that-
1) am not able to install the service , an exception gets raised. As a result "the windows marks my service for deletion."
here is the code-
private static int localPort = 6000 ;
private static UdpClient receivingUdpClient = new UdpClient(localPort);
private static IPEndPoint RemoteIpEndPoint = null ;
private static FileStream fs;
private static byte[] receiveBytes = new byte[0];
public static void ReceiveFile()
{
try
{
// Receive file
receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint); i++;
fs = new FileStream(@"E:\recd files\temp"+i+"."+"txt", FileMode.Create,
FileAccess.ReadWrite, FileShare.ReadWrite);
fs.Write(receiveBytes, 0, receiveBytes.Length);
Process.Start(fs.Name);
}
catch (Exception e)
{
//Console.WriteLine(e.ToString ());
}
finally
{
fs.Close();
}
}
protected override void OnStart(string[] args)
{
ReceiveFile();
}
any help would be highly appreciated