mirror of https://github.com/schollz/croc.git
Seems to work, need to add data writing
This commit is contained in:
parent
97bb4e1dc5
commit
f4fbf8c23e
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue