From 0f001a7c7c49b1386b5914e9784234b3467f0976 Mon Sep 17 00:00:00 2001 From: amirhnajafiz Date: Thu, 11 Aug 2022 10:18:35 +0430 Subject: [PATCH] update: server --- server.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index 7b7448c..556ce65 100644 --- a/server.go +++ b/server.go @@ -8,6 +8,11 @@ import ( "github.com/amirhnajafiz/stallion/internal" ) +type Server interface { + // Handle method generates a new worker for clients. + Handle(conn net.Conn) +} + // NewServer creates a new broker server on given port. func NewServer(port string) error { // creating a new server @@ -23,8 +28,10 @@ func NewServer(port string) error { // handling our clients for { - conn, _ := listener.Accept() - - serve.Handle(conn) + if conn, er := listener.Accept(); er == nil { + serve.Handle(conn) + } else { + log.Printf("error in client accept: %v\n", er) + } } }