Commit 600b6e45 authored by Harshit Pande's avatar Harshit Pande

code to run different servers and server configuration set up

parent 80cc07bc
package main
import (
//"log"
//"net"
//"net/rpc"
"fmt"
"os"
"reflect"
"strconv"
)
//constant values used
const (
CLIENT_PORT = 9000
)
type ServerConfig struct {
Id int // Id of server. Must be unique
Hostname string // name or ip of host
ClientPort int // port at which server listens to client messages.
LogPort int // tcp port for inter-replica protocol messages.
}
type ClusterConfig struct {
Path string // Directory for persistent log
Servers []ServerConfig // All servers in this cluster
}
func NewServerConfig(server_id int) (*ServerConfig, error) {
this_server := new(ServerConfig)
this_server.Id = server_id
this_server.Hostname = "127.0.0.1"
this_server.ClientPort = CLIENT_PORT
this_server.LogPort = CLIENT_PORT + server_id
return this_server, nil
}
func main() {
server_id, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Println("argument ", os.Args[1], "is not string")
}
this_server, _ := NewServerConfig(server_id)
fmt.Println(reflect.TypeOf(this_server))
}
package main
import (
//"os"
"fmt"
//"log"
"os/exec"
"strconv"
//"syscall"
)
//constant values used
const (
NUM_SERVERS int = 5
)
func TestServersCommunic() {
for i := 0; i < NUM_SERVERS; i++ {
cmd := exec.Command("go", "run", "replic_kvstore.go", strconv.Itoa(i+1), strconv.Itoa(NUM_SERVERS))
out, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(err)
}
fmt.Println(string(out))
}
}
func main() {
TestServersCommunic()
var dummy_input string
fmt.Scanln(&dummy_input)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment