Home > Mobile >  What am i doing wrong here? Golang
What am i doing wrong here? Golang

Time:09-17

I have a problem when I try to connect to php-fpm.service on a Linux machine, the service listens on port 9000, the service works perfectly and this is my code:

package main

import (
    "log"
    "net"
)

func main() {
    listener, err := net.Listen("unix", "127.0.0.1:9000")

    if err != nil {
        log.Fatal("Connection error: ", err)
    }

    for {
        fd, err := listener.Accept()

        if err != nil {
            log.Fatal("Accept error: ", err)
        }

        log.Print("a")
    }
}

The bad thing is that after this line of code: fd, _ := listener.Accept() nothing happens anymore, the code that follows is no longer executed, as you can see in the code above I have this line log.Print("a") but that text is never displayed on the console. What am I doing wrong? I hope you can help me, thanks in advance.

CodePudding user response:

Your issue is likely that you're creating a unix socket with the name "127.0.0.1:9000". The address likely means you want either tcp or udp as the address type.

listener, err := net.Listen("tcp", "127.0.0.1:9000")

With this change, I'm able to connect to the server and see your log message.

  • Related