转至:通过TCP连接写入标头

I've implemented a TCP server with the following code structure from here: http://golang.org/pkg/net/#example_Listener

I'm trying to ping the TCP server from a browser. The TCP server is able to write to my browser. However, it is not able to write to the client header as it is not using the HTTP protocol. How do I keep the TCP protocol and connections but still be able to write to the browser's header?

How do I keep the TCP protocol and connections but still be able to write to the browser's header?

I think you have a misconception regarding the difference between TCP and HTTP. TCP is the transport layer – it defines the way in which IP packets are exchanged between two endpoints. HTTP builds upon TCP and defines a text-oriented protocol for exchanging "hypertext" i.e. content over TCP.

You can write a valid HTTP response to a TCP socket by hand but it doesn't make sense to do so; use the net/http package; it's much safer and will ensure that you get every little detail in the protocol right.