Esempio n. 1
0
        /// <summary>
        /// Pojedyńczy wątek serwera.
        /// </summary>
        public void start()
        {
            NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=postgres;Password=przemek;Database=template1;");
            conn.Open();
            QueryMaker qm = new QueryMaker(conn);

            serverSocket = new TcpListener(ip, port);
            TcpClient clientSocket;

            serverSocket.Start();

            int counter = 0;

            while (true)
            {
                counter += 1;
                clientSocket = serverSocket.AcceptTcpClient();
                HandleClient client = new HandleClient(clientSocket, Convert.ToString(counter), qm);
                Thread thread = new Thread(new ThreadStart(client.getMessage));
                thread.Start();
            }
            //conn.Close();
            clientSocket.Close();
            serverSocket.Stop();

        }
Esempio n. 2
0
 /// <summary>
 /// Tworzymy nowy wątek dla klienta.
 /// </summary>
 /// <param name="inClientSocket"> Obiekt reprezentujący klienta. </param>  
 /// <param name="clientNo"> Numer klienta w kolejce. </param>
 public HandleClient(TcpClient inClientSocket, string clineNo, QueryMaker qm)
 {
     this.clientSocket = inClientSocket;
     this.clNo = clineNo;
     this.qm = qm;
 }
Esempio n. 3
0
        /// <summary>
        /// Metoda obsługująca wciśnięcie przycisku OK.
        /// </summary>
        /// <param name="sender"> Obiekt będący źródłem zdarzenia. </param>
        /// <param name="e"> Parametr zdarzenia. </param>
        protected void bOk_Click(object sender, EventArgs e)
        {
            if (txtB3.Text == "")
            {
                MessageBox.Show("Podaj nazwę użytkownika");
            }
            else if (txtB6.Text == "")
            {
                MessageBox.Show("Podaj hasło");
            }
            else 
            {
                // Połączenie z bazą.
                if (checkpass())
                {
                    NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=postgres;Password=przemek;Database=template1;");
                    conn.Open();


                    mi.Visible = false;
                    parent.subm2.Visible = true;
                    parent.lab1.Visible = true;
                    parent.lab2.Visible = true;
                    parent.lb1.Visible = true;
                    parent.lb2.Visible = true;
                    parent.but1.Visible = true;
                    QueryMaker qm = new QueryMaker(conn);
                    String[] users = qm.getClients();
                    parent.qm = qm;
                    parent.but1.Enabled = true;
                    for (int i = 0; i < users.Length; i+=3)
                    {
                        if (users[i]!=null)
                            parent.lb1.Items.Add(users[i+1]+" ("+ users[i]+")");
                    }

                    //usunąć to !!!!!!!!
                    /*qm.saveMessage(24, 25, "wiadomosc1");
                    qm.saveMessage(25, 24, "odpowiedz1");
                    Dictionary<String, String> dict = qm.getMessage(25);*/
                    Dispose();
                }
                else
                {
                    MessageBox.Show("Niepoprawna nazwa użytkownika i/lub hasło!");
                }
            }
        }