Skip to content
Snippets Groups Projects
Commit 258ebdf4 authored by yshen47's avatar yshen47
Browse files

set to be debug mode

parent 26c24cda
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"strconv" "strconv"
) )
var DEBUG = false var DEBUG = true
func main() { func main() {
......
package main
import (
"bufio"
"fmt"
"net"
"time"
)
func listen (conn net.Conn) {
for {
// read in input from stdin
// listen for reply
message, _ := bufio.NewReader(conn).ReadString('\n')
fmt.Print("Message from server: "+message)
}
}
func main() {
// connect to this socket
conn, _ := net.Dial("tcp", "127.0.0.1:8081")
go listen(conn)
}
package main
import (
"bufio"
"fmt"
"net"
"os"
"strings"
)
func send (conn net.Conn) {
for {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Text to send: ")
text, _ := reader.ReadString('\n')
// send to socket
fmt.Fprintf(conn, text + "\n")
}
}
func main() {
fmt.Println("Launching server...")
// listen on all interfaces
ln, _ := net.Listen("tcp", ":8081")
// accept connection on port
conn, _ := ln.Accept()
go send(conn)
fmt.Println(conn.LocalAddr())
// run loop forever (or until ctrl-c)
for {
// will listen for message to process ending in newline (\n)
message, _ := bufio.NewReader(conn).ReadString('\n')
// output message received
fmt.Print("Message Received:", string(message), "\n")
// sample process for string received
newmessage := strings.ToUpper(message)
// send new string back to client
conn.Write([]byte(newmessage + "\n"))
}
}
\ No newline at end of file
...@@ -27,7 +27,6 @@ type Server struct { ...@@ -27,7 +27,6 @@ type Server struct {
VectorTimestampMutex sync.Mutex VectorTimestampMutex sync.Mutex
messageQueue [] Message messageQueue [] Message
messageQueueMutex sync.Mutex messageQueueMutex sync.Mutex
} }
func (s * Server) Constructor(name string, peopleNum int, portNum int, myAddr string, globalServerAddrs [] string) { func (s * Server) Constructor(name string, peopleNum int, portNum int, myAddr string, globalServerAddrs [] string) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment