PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 22, 2022

[FIXED] What am i doing wrong here? Golang

 October 22, 2022     go, sockets     No comments   

Issue

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.


Solution

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.



Answered By - Stephen Newell
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing