On Sun, Mar 7, 2010 at 7:20 AM, Christopher Wicklein
<
chr...@wicklein.org> wrote:
> Greetings--
> I'm trying to write a bit of Go to exchange binary data over a TCP
> connection. The client connects to the server and writes an int32 in
> network byte order then reads back an int32 in network byte order. The
> following code will compile but does not seem to work. The key problem
> seems to be that the buffer doesn't contain the binary representation of xxx
> in network byte order (fmt.Printf shows an empty slice), but another concern
> is how read knows to stop reading at four bytes. Does the size of the slice
> tell Read what to do?
Yes, this is the problem. It ought to work if you use slice with room
for some data. Try changing
and it should read four bytes at a time (instead of zero bytes).