I wouldn't say 255 bytes is a large buffer. Are you concerned that the
Read will block until at least 255 bytes are Read? You can mitigate
this with the SetReadTimeout function:
http://golang.org/pkg/net/#TCPConn.SetReadTimeout
The example you've posted will only read the first 255 bytes, but I
presume you know that. You should write another for loop inside the
main one to Read until the connection closes.
> What if more than 255 bytes are sent and the data gets truncated? Is there a
> way to determine the size of the incoming data and allocate properly? I
> tried to follow the Web.go project as an example but kept getting lost
> trying to follow all the structs...
If more than 255 bytes are sent, you'll need to perform additional
Reads from the connection and Write them back.
I wrote a TCP<->HTTP<->TCP tunnel in Go, which demonstrates some of
this stuff. I wrote it a little while ago, so there are probably
cleaner and more idiomatic ways of doing it, but it's worth checking
out: (client is simpler than server)
http://github.com/nf/gohttptun
Andrew