yokzu

yokzu

  • NA
  • 306
  • 0

About socket programming

Jan 7 2010 2:33 PM
Hi,

My server side codes are below.  When I click the button first time at client side, data isnt going to server side. When I click second and third times, data is going normally. Why data isnt going at first click?


        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(4444);
            tcp_listener.Start();
            istemcisoketi = tcp_listener.AcceptSocket();

            if (istemcisoketi.Connected)
            {
                while (true)
                {
                    istemcisoketi = tcp_listener.AcceptSocket();
                    ag_akimi = new NetworkStream(istemcisoketi);
                    akim_okuyucu = new StreamReader(ag_akimi);
                    akim_yazici = new StreamWriter(ag_akimi);
                    try
                    {
                        gelen_veri = akim_okuyucu.ReadLine();
                        if (gelen_veri.EndsWith("??"))
                        {
                            yaz(gelen_veri);
                        }

                    }
                    catch
                    {
                        return;
                    }
                  
                }
            }

        }


        public void yaz(string e)
        {
            sunucu_bag.Open();
            OleDbCommand cmd_veriyi_yaz = new OleDbCommand("INSERT INTO notlar (iletiler,tarih) VALUES ('" + e + "' , '" + DateTime.Now + "')", sunucu_bag);
            cmd_veriyi_yaz.ExecuteNonQuery();
            sunucu_bag.Close();
           
        }



Answers (2)