Listening Port Permanently. if file is on my stream, Get file. How to?

Posted by Phsika on Stack Overflow See other posts from Stack Overflow or by Phsika
Published on 2010-05-08T14:13:07Z Indexed on 2010/05/08 14:18 UTC
Read the original article Hit count: 151

i writed 2 client and server program. client dend file also server listen port and than get file.But i need My server App must listen on 51124 port permanently. if any file on my stream, show my message "there is a file on your stream" and than show me savefile dialog. But my server app in "Infinite loop".

1) listen 51124 port every time
2) do i have a file on my stream, show me a messagebox.



   private void Form1_Load(object sender, EventArgs e)
        {

            TcpListener Dinle = new TcpListener(51124);
            try
            {

                Dinle.Start();

                Socket Baglanti = Dinle.AcceptSocket();
                if (!Baglanti.Connected)
                {
                    MessageBox.Show("No Connection!");
                }

                else
                {
                    while (true)
                    {
                        byte[] Dizi = new byte[250000];
                        Baglanti.Receive(Dizi, Dizi.Length, 0);

                        string Yol;

                        saveFileDialog1.Title = "Save File";
                        saveFileDialog1.ShowDialog();
                        Yol = saveFileDialog1.FileName;
                        FileStream Dosya = new FileStream(Yol, FileMode.Create);
                        Dosya.Write(Dizi, 0, Dizi.Length - 20);
                        Dosya.Close();
                        listBox1.Items.Add("dosya indirildi");
                        listBox1.Items.Add("Dosya Boyutu=" + Dizi.Length.ToString());
                        listBox1.Items.Add("Indirilme Tarihi=" + DateTime.Now);
                        listBox1.Items.Add("--------------------------------");
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }

        }

My Algorithm:

if(AnyFileonStream()==true) { GetFile()

//Also continue to listening 51124 port... }

How can i do that?

© Stack Overflow or respective owner

Related posts about c#

Related posts about socket-programming