#incoming, err := conn.Read(buffer) EOF error
47 messages ยท Page 1 of 1 (latest)
Ah nevermind; you edited.
Can you share a code snippet?
Hard to tell what you might be doing wrong otherwise.
func handleIncomingRequest(conn net.Conn) {
defer conn.Close()
// store incoming data
buffer := make([]byte, 1024)
incoming, err := conn.Read(buffer)
if err != nil {
fmt.Println("handleIncomingRequest loop error")
log.Fatal(err)
}
fmt.Println(incoming)
// respond
conn.Write([]byte("test\n"))
}
You have to write a header prior to the body.
It looks like you're handling raw TCP sockets here.
Why not use net/http?
Haha. That's a good reason. ๐
net/http has a full featured http server. There are good examples in the docs
Give it a try and let us know if you run into problems.
will this solve the
this page isn't working
localhost send invalid response
ERR_INVALID_HTTP_RESPONSE
problem or
2023/03/29 16:35:54 EOF
?
okay I'll return when I read it and apply to my code. Thanks!
I wrote(stole) this code I got how it works
package main
import (
"fmt"
"net/http"
)
func respond(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "Works!\n")
}
func main() {
http.HandleFunc("/", respond)
http.ListenAndServe(":7777", nil)
}
How can I make this site show up every time user tries to go a site.
if I add localhost:7777 to proxy settings and run my code I get
ERR_TUNNEL_CONNECTION_FAILED
but if I add localhost to proxy but don't run code I get
ERR_TUNNEL_CONNECTION_FAILED (as normal)
shortly I want user to get 'Works!' text whenever they tries to connect a site
I'm not sure how to setup your proxy, actually. Maybe someone else can help with that.
You're not going to be able to run a website from your local PC that others can visit without a lot of networking black magic I don't fully understand.
Presuming that's your goal.
no I don't want others. Just local user
strange computer project that teacher gave me
I'm surprised localhost:7777 doesn't work. Do you own the machine you're connecting on, or are you at work?
Oh.
If you're on a school network there's no telling what they've done.
I'm currently on my pc
weeeird
So opening up http://localhost:7777/ in a browser doesn't show "Works!" in the browser?
no it shows
I want to every site that user open shows~~ the content~~ the response from localhost:7777
I'm not sure how to make that happen.
proxy is a gate between pc and internet right?
Yeah but unless you've got something running on the router or something I think they're optional.
Like, anyone with admin access on the PC can change the proxy settings themselves (if they know how)
Then hopefully he's taught you what you need to know. I don't know. ๐
the teacher wants students to connect only 1 site
I thought I can give that site using proxy every time they tries to get something
this will block everything on computer(like discord messages, windows updates) but teacher said they're not important.
I don't think any of students can think turning the proxy off (except me because I'm making that lol)
teacher is just trying to give 20min youtube indian level python education to students. but the guy next to teacher downloaded steam and started playing CS ๐
the teacher is the weirdest people I've ever met