Echo server: Difference between revisions

Content added Content deleted
m (Fixed alphabetic position)
No edit summary
Line 480: Line 480:
12321 echo-server</lang>
12321 echo-server</lang>
''TODO: use tasker.fs and non-blocking semantics to handle mutliple connections''
''TODO: use tasker.fs and non-blocking semantics to handle mutliple connections''

=={{header|Go}}==
<lang go>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)
}
}
</lang>


=={{header|Haskell}}==
=={{header|Haskell}}==