Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Echo-server/Go/echo-server.go
Normal file
31
Task/Echo-server/Go/echo-server.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"bufio"
|
||||
)
|
||||
|
||||
func echo(s net.Conn, i int) {
|
||||
defer s.Close();
|
||||
|
||||
fmt.Printf("%d: %v <-> %v\n", i, s.LocalAddr(), s.RemoteAddr())
|
||||
b := bufio.NewReader(s)
|
||||
for {
|
||||
line, e := b.ReadBytes('\n')
|
||||
if e != nil {
|
||||
break
|
||||
}
|
||||
s.Write(line)
|
||||
}
|
||||
fmt.Printf("%d: closed\n", i)
|
||||
}
|
||||
|
||||
func main() {
|
||||
l, e := net.Listen("tcp", ":12321")
|
||||
for i := 0; e == nil; i++ {
|
||||
var s net.Conn
|
||||
s, e = l.Accept()
|
||||
go echo(s, i)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue