Seems to work, need to add data writing

This commit is contained in:
Zack Scholl 2017-10-17 12:11:39 -06:00
parent 97bb4e1dc5
commit f4fbf8c23e
2 changed files with 26 additions and 1 deletions

View File

@ -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)

View File

@ -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
}