goDDOS/server/main.go
server/main.goRaw
1package main
2
3import (
4 "bufio"
5 "fmt"
6 "net"
7 "os"
8)
9
10const (
11 CONN_HOST = "localhost"
12 CONN_PORT = "3333"
13 CONN_TYPE = "tcp"
14)
15
16func main() { //server
17
18 fmt.Println("Launching server...")
19
20 // listen on all interfaces
21 ln, err := net.Listen(CONN_TYPE, CONN_HOST+":"+CONN_PORT)
22 if err != nil {
23 fmt.Println("Error listening:", err.Error())
24 os.Exit(1)
25 }
26
27 // Close the listener when the application closes.
28 defer ln.Close()
29 defer fmt.Println("ended")
30
31 fmt.Println("Listening on " + CONN_HOST + ":" + CONN_PORT)
32
33 // accept connection on port
34 c, err := ln.Accept()
35 if err != nil {
36 fmt.Println("Error accepting: ", err.Error())
37 os.Exit(1)
38 }
39 // will listen for message to process ending in newline (\n)
40 message, _ := bufio.NewReader(c).ReadString('\n')
41 // output message received
42 fmt.Print("client connected:", string(message), "\n")
43 for {
44 /*// will listen for message to process ending in newline (\n)
45 message, _ := bufio.NewReader(c).ReadString('\n')
46 // output message received
47 fmt.Print("client connected:", string(message), "\n")*/
48
49 newcommand := bufio.NewReader(os.Stdin)
50 fmt.Print("command to send to the clients: ")
51 text, _ := newcommand.ReadString('\n')
52 // send new string back to client
53 c.Write([]byte(text + "\n"))
54 }
55}