mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
Seems to work, need to add data writing
This commit is contained in:
parent
97bb4e1dc5
commit
f4fbf8c23e
2 changed files with 26 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func runClient(connectionType string, codePhrase string) {
|
func runClient(connectionType string, codePhrase string) {
|
||||||
|
@ -26,6 +27,17 @@ func runClient(connectionType string, codePhrase string) {
|
||||||
if connectionType == "s" {
|
if connectionType == "s" {
|
||||||
message = receiveMessage(connection)
|
message = receiveMessage(connection)
|
||||||
fmt.Println(message)
|
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)
|
}(id)
|
||||||
|
|
|
@ -90,19 +90,32 @@ func clientCommuncation(id int, connection net.Conn) {
|
||||||
fmt.Println("waiting for reciever")
|
fmt.Println("waiting for reciever")
|
||||||
connections.RLock()
|
connections.RLock()
|
||||||
if _, ok := connections.reciever[codePhrase]; ok {
|
if _, ok := connections.reciever[codePhrase]; ok {
|
||||||
|
connections.RUnlock()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
connections.RUnlock()
|
connections.RUnlock()
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
sendMessage("ok", connection)
|
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 {
|
} else {
|
||||||
fmt.Println("Got reciever")
|
fmt.Println("Got reciever")
|
||||||
connections.Lock()
|
connections.Lock()
|
||||||
connections.reciever[codePhrase] = connection
|
connections.reciever[codePhrase] = connection
|
||||||
connections.Unlock()
|
connections.Unlock()
|
||||||
}
|
}
|
||||||
fmt.Println(message)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue