On Mon, Oct 30, 2017, 7:55 PM <2891132l...@gmail.com> wrote:

> I write this code in the follwings:
> package main
>
> import (
> "fmt"
> "net"
> "os"
> )
>
> func main() {
> service := ":5000"
> tcpAddr, err := net.ResolveTCPAddr("tcp", service)
> checkError(err)
> listener, err := net.ListenTCP("tcp", tcpAddr)
> checkError(err)
> for i := 0; i < 10; i++ {
> conn, err := listener.Accept()
> if err != nil {
> continue
> }
> handleClient(conn)
> conn.Close()
> }
> }
> func handleClient(conn net.Conn) {
> var buf [512]byte
> for {
> n, err := conn.Read(buf[0:])
> if err != nil {
> return
> }
> rAddr := conn.RemoteAddr()
> fmt.Println("receive from client", rAddr.String(), string(buf[0:n]))
> _, err2 := conn.Write([]byte("welcome client!"))
> if err2 != nil {
> return
> }
> }
> }
> func checkError(err error) {
> if err != nil {
> fmt.Fprintf(os.Stderr, "fatal error: %s", err.Error())
> os.Exit(1)
> }
> }
>
>
> I try to run it in Sublime Text3 but it has no reaction
>

It is a server program, waiting for connections from a client. When you say
it has no reactions, does that mean it doesn't respond to client
connections, or that it is not doing some other kind of expected behaviour
when you run it? Can you be more specific about what you have tried, what
you expected, and what actually happened?

and I try to run it in running windows, it shows:
> fatal error: lsiten tcp:5000:bind:Only one usage of each socket
> address(protocol/network address/port) is normally permitted.exit status 1
>

If your server program still running within SublimeText and listening on
that port?


> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to