A
A
Andrey Fomin2021-02-04 20:31:42
SQLite
Andrey Fomin, 2021-02-04 20:31:42

What is the best way to implement the work of a client-server application?

Hello!
There is a simple program and a simple server written in C #, the program has buttons, when clicked, data should be loaded from the database into textboxes, this is all great, I know how to do it, but how to do the same implementation with using the server, ideally when a button is pressed, for example, to add a new user, the data from textboxes is read, added to the sql query, and now I need to somehow convey this query to the database through the server, how can this be easier to implement?
Here is the server code, maybe it will help

using System;
using System.Net;
using System.Net.Sockets;
using Microsoft.Data.Sqlite;

namespace Server
{
    class Program
    {
        const int port = 8888;
        SqliteConnection load = new SqliteConnection("Data source = accounts.db");
        static void Main(string[] args)
        {
            TcpListener server = null;
            try
            {
                IPAddress localAddr = IPAddress.Parse("127.0.0.1");
                server = new TcpListener(localAddr, port);

                // запуск слушателя
                server.Start();

                while (true)
                {
                    Console.WriteLine("Ожидание подключений... ");

                   
                    TcpClient client = server.AcceptTcpClient();
                    Console.WriteLine("Клиент подключился к серверу.");

                    while (client.Connected)
                    {
                        NetworkStream stream = client.GetStream();
                       


                        stream.Close();

                    }
                    client.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
Griboks, 2021-02-04
@Griboks

Why do you need a server? The server is not needed here. But if you really want to, you can write a sql proxy.

V
Vasily Bannikov, 2021-02-04
@vabka

It's better to use asp net core instead of TcpListener .
From the client, you just need to send http requests.

A
Alexander Lykasov, 2021-02-05
@lykasov-aleksandr

Quite a strange application architecture. For educational purposes, of course, it will do, but in real conditions, they usually don’t drive sql from the client to the server, but make a server API that provides the necessary operations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question