From f4fbf8c23e9d2b55c78d40c2f80428458a6a7bf5 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 17 Oct 2017 12:11:39 -0600 Subject: [PATCH] Seems to work, need to add data writing --- test/client.go | 12 ++++++++++++ test/server.go | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/test/client.go b/test/client.go index 1b1bc9d..9c03166 100644 --- a/test/client.go +++ b/test/client.go @@ -5,6 +5,7 @@ import ( "net" "strconv" "sync" + "time" ) func runClient(connectionType string, codePhrase string) { @@ -26,6 +27,17 @@ func runClient(connectionType string, codePhrase string) { if connectionType == "s" { message = receiveMessage(connection) fmt.Println(message) + // TODO: Write data from file + // Send file name + sendMessage("filename", connection) + // Send file size + time.Sleep(3 * time.Second) + sendMessage("filesize", connection) + } else { + // TODO: Pull data and write to file + fileName := receiveMessage(connection) + fileSize := receiveMessage(connection) + fmt.Println(fileName, fileSize) } }(id) diff --git a/test/server.go b/test/server.go index 58aa304..058c509 100644 --- a/test/server.go +++ b/test/server.go @@ -90,19 +90,32 @@ func clientCommuncation(id int, connection net.Conn) { fmt.Println("waiting for reciever") connections.RLock() if _, ok := connections.reciever[codePhrase]; ok { + connections.RUnlock() break } connections.RUnlock() time.Sleep(100 * time.Millisecond) } sendMessage("ok", connection) + fmt.Println("preparing pipe") + connections.Lock() + con1 := connections.sender[codePhrase] + con2 := connections.reciever[codePhrase] + connections.Unlock() + fmt.Println("piping connections") + Pipe(con1, con2) + fmt.Println("done piping") + connections.Lock() + delete(connections.sender, codePhrase) + delete(connections.reciever, codePhrase) + connections.Unlock() + fmt.Println("deleted " + codePhrase) } else { fmt.Println("Got reciever") connections.Lock() connections.reciever[codePhrase] = connection connections.Unlock() } - fmt.Println(message) return }