CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
29
Task/Echo-server/Go/echo-server.go
Normal file
29
Task/Echo-server/Go/echo-server.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"bufio"
|
||||
)
|
||||
|
||||
func echo(s net.Conn, i int) {
|
||||
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