Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/hex"
- "fmt"
- "net"
- )
- func main() {
- port := ":8888"
- tcpAddr, err := net.ResolveTCPAddr("tcp", port)
- if err != nil {
- panic(err)
- }
- listner, err := net.ListenTCP("tcp", tcpAddr)
- if err != nil {
- panic(err)
- }
- for {
- conn, err := listner.Accept()
- if err != nil {
- continue
- }
- go handle(conn)
- }
- }
- func handle(conn net.Conn) {
- defer conn.Close()
- conn.Write([]byte("Command: "))
- command := make([]byte, 64)
- _, err := conn.Read(command)
- if err != nil {
- panic(err)
- }
- dump := hex.Dump(command)
- fmt.Println(dump)
- if string(command) == "hello" {
- conn.Write([]byte("Hello\n"))
- } else {
- conn.Write([]byte("Good bye\n"))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement