From ef3cfc26b5c0a3afdc40c3bb41ec714ffd794762 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 17 Oct 2017 11:32:08 -0600 Subject: [PATCH] seems to be an idea to work from --- test/client.go | 2 +- test/main.go | 4 +++- test/server.go | 28 ++++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/test/client.go b/test/client.go index 7f54faf..e0325bb 100644 --- a/test/client.go +++ b/test/client.go @@ -27,7 +27,7 @@ func runClient() { connection.Read(messageByte) message = strings.Replace(string(messageByte), ":", "", -1) fmt.Println(message) - message = fillString("reciever-123", 64) + message = fillString("r.1-2-3", 64) connection.Write([]byte(message)) }(id) diff --git a/test/main.go b/test/main.go index 63f0b4a..c4cc914 100644 --- a/test/main.go +++ b/test/main.go @@ -14,11 +14,13 @@ const numberConnections = 1 var server, file string // Global varaibles -var serverAddress, fileName string +var serverAddress, fileName, codePhraseFlag, connectionTypeFlag string func main() { flag.StringVar(&serverAddress, "server", "", "(run as client) server address to connect to") flag.StringVar(&fileName, "file", "", "(run as server) file to serve") + flag.StringVar(&codePhraseFlag, "code", "", "(run as server) file to serve") + flag.StringVar(&connectionTypeFlag, "type", "", "(run as server) file to serve") flag.Parse() // Check build flags too, which take precedent if server != "" { diff --git a/test/server.go b/test/server.go index fbb3bda..7a70c6b 100644 --- a/test/server.go +++ b/test/server.go @@ -11,6 +11,21 @@ import ( log "github.com/sirupsen/logrus" ) +type connectionMap struct { + reciever map[string]net.Conn + sender map[string]net.Conn + sync.RWMutex +} + +var connections connectionMap + +func init() { + connections.Lock() + connections.reciever = make(map[string]net.Conn) + connections.sender = make(map[string]net.Conn) + connections.Unlock() +} + func runServer() { logger := log.WithFields(log.Fields{ "function": "main", @@ -59,10 +74,19 @@ func listener(id int) (err error) { } func clientCommuncation(id int, connection net.Conn) { - defer connection.Close() sendMessage("who?", connection) message := receiveMessage(connection) - // TODO: parse message for sender/reciever and the code phrase + connectionType := strings.Split(message, ".")[0] + codePhrase := strings.Split(message, ".")[1] + // If reciever + connections.Lock() + connections.reciever[codePhrase] = connection + connections.Unlock() + + if connectionType == "s" { + // periodically check if the receiver has joined + + } fmt.Println(message) return }