-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (39 loc) · 873 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
// "fmt"
"log"
"net/http"
"os"
)
var infoLog *log.Logger
var panicLog *log.Logger
func initLogs() {
logFile, err := os.OpenFile("logs.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
log.Fatal("Failed to open log file:", err)
}
infoLog = log.New(logFile, "INFO: ", log.LstdFlags)
panicLog = log.New(logFile, "ERROR: ", log.LstdFlags)
}
func main() {
initLogs()
go func() {
http.HandleFunc("/ws", HandleConnections)
infoLog.Println("http server started on :8080")
err := http.ListenAndServe(":8080", nil)
if err != nil {
panicLog.Fatalln("ListenAndServe: ", err)
}
}()
go Sniff()
go func() {
cnt := 0
for packet := range packet_channel {
// fmt.Println("Packet received:", packet)
packet_json := ParsePacket(packet)
BroadcastToConnections(packet_json)
cnt++
}
}()
select {}
}