mirror of https://github.com/schollz/croc.git
seems to be an idea to work from
This commit is contained in:
parent
67919b697f
commit
ef3cfc26b5
|
@ -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)
|
||||
|
|
|
@ -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 != "" {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue