This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func sendToClient(ip string, port int, from string, message string) { | |
client, err := rpc.DialHTTP("tcp", ip+":"+strconv.Itoa(port)) | |
if err != nil { | |
log.Printf("dialing: %v\n", err.Error()) | |
} | |
var response int | |
error := client.Call("Client.Deliver", fmt.Sprintf("%v,%v", from, message), &response) | |
if error != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (s *Server) Send(request string, response *string) error { | |
log.Printf("incoming message: %v", request) | |
parts := strings.Split(request, ",") | |
for username, c := range s.clients { | |
if username != parts[0] { | |
sendToClient(c.Ip, c.Port, parts[0], parts[1]) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (s *Server) SignOut(request string, response *string) error { | |
if request == "" { | |
*response = "empty request. sign out failed" | |
} else { | |
if s.clients == nil { | |
*response = "you are not signed in" | |
} else if _, ok := s.clients[request]; !ok { | |
*response = "you are not signed in" | |
} else { | |
delete(s.clients, request) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Server struct { | |
clients map[string]client.Client | |
} | |
func (s *Server) SignIn(request string, response *string) error { | |
if request == "" { | |
*response = "empty request. sign in failed" | |
} else { | |
parts := strings.Split(request, ",") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm -f out | |
mkfifo out | |
trap "rm -f out" EXIT | |
while true | |
do | |
cat out | nc -l 1500 > >( # parse the netcat output, to build the answer redirected to the pipe "out". | |
export REQUEST= | |
while read line | |
do | |
line=$(echo "$line" | tr -d '[\r\n]') |