Created
August 19, 2019 07:21
-
-
Save ptflp/a4c41558787ea839b76931351eb3c33a to your computer and use it in GitHub Desktop.
Check Xdebug connection on golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net" | |
"os" | |
) | |
const ( | |
CONN_INTERFACE = "0.0.0.0" | |
CONN_PORT = "9000" | |
CONN_TYPE = "tcp4" | |
) | |
func main() { | |
// Listen for incoming connections. | |
l, err := net.Listen(CONN_TYPE, CONN_INTERFACE+":"+CONN_PORT) | |
if err != nil { | |
fmt.Println("Error listening:", err.Error()) | |
os.Exit(1) | |
} | |
// Close the listener when the application closes. | |
defer l.Close() | |
fmt.Println("Listening on " + CONN_INTERFACE + ":" + CONN_PORT) | |
for { | |
// Listen for an incoming connection. | |
conn, err := l.Accept() | |
if err != nil { | |
fmt.Println("Error accepting: ", err.Error()) | |
os.Exit(1) | |
} | |
// Handle connections in a new goroutine. | |
go handleRequest(conn) | |
} | |
} | |
// Handles incoming requests. | |
func handleRequest(conn net.Conn) { | |
// Make a buffer to hold incoming data. | |
buf := make([]byte, 1024) | |
// Read the incoming connection into the buffer. | |
reqLen, err := conn.Read(buf) | |
fmt.Println("Xdebug request length must be ~517 ") | |
fmt.Printf("Length: %d \n", reqLen) | |
if err != nil { | |
fmt.Println("Error reading:", err.Error()) | |
} | |
conn.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment