-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.go
48 lines (43 loc) · 953 Bytes
/
listener.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
package main
import (
"fmt"
"net"
"os"
)
const (
CONN_HOST = "localhost"
CONN_PORT = "3333"
)
/*
func (s *Server) ListenAndServe() error {
l, err := net.Listen("tcp", s.Addr)
if err != nil {
return err
}
defer l.Close()
return s.Serve(l)
}
*/
func main() {
// Listen for incoming connections.
l, err := net.Listen("tcp", ":"+CONN_PORT)
if err != nil {
fmt.Println("Error listening:", err.Error())
os.Exit(1)
}
// Close the listener when the application closes.
defer l.Close()
fmt.Println("Listening on " + CONN_HOST + ":" + CONN_PORT)
prox := new(SNIProxy);
for {
// Listen for an incoming connection.
conn, err := l.Accept()
if err != nil {
fmt.Println("Error accepting: ", err.Error())
// FIXME
os.Exit(1)
}
// Handle connections in a new goroutine.
go prox.ServeTCP(conn);
}
}