#incoming, err := conn.Read(buffer) EOF error

47 messages ยท Page 1 of 1 (latest)

lime flower
#

690 and 710 are improper HTTP response codes.... is that what your browser is saying?

#

Ah nevermind; you edited.

#

Can you share a code snippet?

#

Hard to tell what you might be doing wrong otherwise.

upbeat niche
#
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"))
}
lime flower
#

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?

upbeat niche
#

because I don't know

#

I can use

lime flower
#

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.

upbeat niche
#

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
?

lime flower
#

The first one.

#

The EOF is happening when the browser hangs up

#

So both, actually.

upbeat niche
#

okay I'll return when I read it and apply to my code. Thanks!

upbeat niche
#

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)

upbeat niche
#

shortly I want user to get 'Works!' text whenever they tries to connect a site

lime flower
#

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.

upbeat niche
#

no I don't want others. Just local user

#

strange computer project that teacher gave me

lime flower
#

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.

upbeat niche
#

I'm currently on my pc

lime flower
#

weeeird

upbeat niche
#

no it shows

lime flower
#

Oh.

#

Then what's the problem?

upbeat niche
#

I want to every site that user open shows~~ the content~~ the response from localhost:7777

lime flower
#

I'm not sure how to make that happen.

upbeat niche
#

proxy is a gate between pc and internet right?

lime flower
#

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. ๐Ÿ™‚

upbeat niche
#

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