seems to be an idea to work from

This commit is contained in:
Zack Scholl 2017-10-17 11:32:08 -06:00
parent 67919b697f
commit ef3cfc26b5
3 changed files with 30 additions and 4 deletions

View File

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

View File

@ -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 != "" {

View File

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