yokzu

yokzu

  • NA
  • 306
  • 0

Connection control

Jan 10 2010 8:15 AM
Hi.
I am trying to make a client and a server. Server must be work always and sometimes I open and close the client program. When client is opened, I want to show a message on server side "client connected". Then if client program closed, there should be a message on server side "client unconnected.". I mean I want to control connected or unconnected always.

My codes are below; if client opened, "connected" message appeared. But when client closed, I couldnt see any message.

How can I control this?

public void Form1_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
            thread_dinleyici = new Thread(new ThreadStart(dinle));
            thread_dinleyici.Start();
        }


        public void dinle()
        {
            tcp_listener = new TcpListener(3333);
            tcp_listener.Start();
            while (true)
            {
                try
                {
                    istemcisoketi = tcp_listener.AcceptSocket();
                    if (istemcisoketi.Connected)
                    {
                        label1.Text = "connected";
                    }
                    else
                    {
                        label1.Text = "unconnected";
                    }
                }
                catch
                {
                  
                }
            }
        }

Answers (4)