IR53C/tcp.go
2022-02-25 06:19:12 -08:00

36 lines
684 B
Go

package e2eirc
import (
"fmt"
"net"
"os"
"strconv"
)
func startTCP(host string, port int) {
// Listen for incoming connections.
l, err := net.Listen("tcp", host+":"+strconv.Itoa(port))
if err != nil {
fmt.Println("Error listening:", err.Error())
os.Exit(1)
}
// Close the listener when the application closes.
defer l.Close()
for {
// Listen for an incoming connection.
conn, err := l.Accept()
if err != nil {
fmt.Println("Error accepting: ", err.Error())
os.Exit(1)
}
// Handle connections in a new goroutine.
go handleRequest(conn)
}
}
// Handles incoming requests.
func handleRequest(conn net.Conn) {
connectionWithNetworkConnection(&conn)
}