From a33546fbedd28a0f29c68a5457af1558c6a75faf Mon Sep 17 00:00:00 2001 From: Dieter Lang Date: Tue, 11 Aug 2026 13:26:05 +0200 Subject: [PATCH] =?UTF-8?q?Ger=C3=A4teerkennung=20ohne=20Datenverbindungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/rs2322tcp-server/main.go | 56 +++++++++++++++++++++++++++++----- internal/client/application.go | 27 ++++------------ 2 files changed, 55 insertions(+), 28 deletions(-) diff --git a/cmd/rs2322tcp-server/main.go b/cmd/rs2322tcp-server/main.go index f6b367b..60ac62a 100644 --- a/cmd/rs2322tcp-server/main.go +++ b/cmd/rs2322tcp-server/main.go @@ -1,12 +1,9 @@ /* Package main implements the rs2322tcp server application. -The server will provide the network endpoint for rs2322tcp clients -and connect incoming connections to configured physical RS232 -interfaces. - -At this stage the application only provides the basic program -structure and version information. +The server provides the network endpoint for rs2322tcp clients +and connects incoming data connections to configured physical +RS232 interfaces. Project: rs2322tcp Module: git.lang-dieter.de/rs2322tcp @@ -14,11 +11,56 @@ Module: git.lang-dieter.de/rs2322tcp package main import ( + "flag" "fmt" + "log" + "git.lang-dieter.de/rs2322tcp/internal/config" + "git.lang-dieter.de/rs2322tcp/internal/server" "git.lang-dieter.de/rs2322tcp/internal/version" ) func main() { - fmt.Printf("rs2322tcp-server %s\n", version.Version) + configFile := flag.String( + "config", + "./configs/server.json", + "Pfad zur Server-Konfigurationsdatei", + ) + + flag.Parse() + + cfg, err := config.LoadServer(*configFile) + if err != nil { + log.Fatalf("Server-Konfiguration laden: %v", err) + } + + controlServer, err := server.NewControlServer(cfg) + if err != nil { + log.Fatalf("Control-Server erstellen: %v", err) + } + + if err := controlServer.Listen(); err != nil { + log.Fatalf("Control-Server starten: %v", err) + } + + defer controlServer.Close() + + fmt.Printf( + "rs2322tcp-server %s\n", + version.Version, + ) + + fmt.Printf( + "Control-Server gestartet auf %s\n", + controlServer.Addr(), + ) + + fmt.Printf( + "Geräte: %d\n", + len(cfg.Devices), + ) + + if err := controlServer.Serve(); err != nil { + log.Fatalf("Control-Server beendet: %v", err) + } } diff --git a/internal/client/application.go b/internal/client/application.go index 2d75751..f4a69a0 100644 --- a/internal/client/application.go +++ b/internal/client/application.go @@ -94,14 +94,14 @@ func NewApplication(configFile string) (*Application, error) { // Start /////////////////////////////////////////////////////////////////////////////// -// Start loads the client configuration, connects to the server and starts -// the client Runtime. +// Start loads the client configuration and connects to the server. // // Start is intended for the initial application startup. An already running // application must be stopped first by calling Close or Reconnect. // -// The Runtime runs asynchronously because it waits for the configured -// bridges while the GUI must remain responsive. +// The server device list is retrieved during startup. The client Runtime is +// not started here; data connections are established separately when the +// runtime is explicitly started. func (a *Application) Start() error { if a == nil { return fmt.Errorf("application is nil") @@ -140,32 +140,17 @@ func (a *Application) Start() error { return fmt.Errorf("get remote devices: %w", err) } - manager := NewVirtualPortManager(cfg.VirtualPortRange) - - runtime, err := NewRuntime(client, manager) - if err != nil { - _ = client.Close() - - return fmt.Errorf("create client runtime: %w", err) - } - - runtimeDone := make(chan error, 1) - a.mu.Lock() a.config = cfg a.client = client - a.runtime = runtime + a.runtime = nil a.devices = append( []transport.RemoteDeviceInfo(nil), devices..., ) - a.runtimeDone = runtimeDone + a.runtimeDone = nil a.mu.Unlock() - go func() { - runtimeDone <- runtime.Run(*cfg) - }() - return nil }