Spaces:
Runtime error
Runtime error
package server | |
import ( | |
"fmt" | |
"log" | |
"net" | |
"NextConnect/utils" | |
) | |
func Start() { | |
config := utils.LoadConfig() | |
listenAddr := fmt.Sprintf("%s:%d", config.Server.BindAddr, config.Server.BindPort) | |
var listener net.Listener | |
var err error | |
// 如果启用了加密,则使用TLS | |
if config.Proxy.EncryptionEnabled { | |
// 这里需要实现TLS监听器 | |
// 暂时使用普通TCP监听器 | |
listener, err = net.Listen("tcp", listenAddr) | |
if err != nil { | |
log.Fatalf("Failed to listen on %s: %v", listenAddr, err) | |
} | |
} else { | |
listener, err = net.Listen("tcp", listenAddr) | |
if err != nil { | |
log.Fatalf("Failed to listen on %s: %v", listenAddr, err) | |
} | |
} | |
defer listener.Close() | |
log.Printf("Server listening on %s", listenAddr) | |
for { | |
conn, err := listener.Accept() | |
if err != nil { | |
log.Printf("Failed to accept connection: %v", err) | |
continue | |
} | |
go handleConnection(conn) | |
} | |
} |