-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from simple-rules/ricl-loghost
Ricl loghost
- Loading branch information
Showing
3 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"net" | ||
"os" | ||
) | ||
|
||
const ( | ||
CONN_HOST = "localhost" | ||
CONN_PORT = "3000" | ||
CONN_TYPE = "tcp" | ||
CONN_URL = CONN_HOST + ":" + CONN_PORT | ||
) | ||
|
||
func main() { | ||
// Listen for incoming connections. | ||
l, err := net.Listen(CONN_TYPE, CONN_URL) | ||
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_URL) | ||
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) { | ||
for { | ||
data, err := bufio.NewReader(conn).ReadString('\n') | ||
if err != nil { | ||
fmt.Println("Error reading:", err.Error()) | ||
break | ||
} | ||
fmt.Println(data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters