# Is there a maximum size for the receive in a TCPSocket as in str = streamSock.recv( 64000 )?

**URL:** <https://www.ruby-forum.com/t/is-there-a-maximum-size-for-the-receive-in-a-tcpsocket-as-in-str-streamsock-recv-64000/124338>\
**Category:** Ruby\
**Created:** [December 27, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/is-there-a-maximum-size-for-the-receive-in-a-tcpsocket-as-in-str-streamsock-recv-64000/124338 "2007-12-27T19:30:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [December 27, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/is-there-a-maximum-size-for-the-receive-in-a-tcpsocket-as-in-str-streamsock-recv-64000/124338/1 "2007-12-27T19:30:48Z")

</div>

Hello Team,

Is there a limit on the amount of data (bytes) that can be received via  
the  
_str = streamSock.recv( 64000 )_ stmt below?  
Although I put \*64000 \*bytes, I consistently do not get more than  
_5562_bytes.  
When this happens the server side fails with a _`write`: broken  
(Errno::EPIPE)_ msg.  
I know that the variable, _userCMD\_output_ contains all the data, since  
I  
printed to the screen for testing.

Thank you

This is the server code:

```
    require 'socket'
    port = 19557
    server = TCPServer.new("", port)

    while (session = server.accept)
            input = session.gets
            userCMD_output = `#{input}`
            session.write("#{userCMD_output}")
            session.close
    end

```

This is the client code:

def runIt( srvr, comm )  
require ‘socket’  
port = 19557  
streamSock = TCPSocket.new( srvr, port )  
streamSock.puts("#{comm}\n")  
str = streamSock.recv( 64000 )  
puts “Output from Server: #{srvr}”  
print str  
puts “\n”  
streamSock.close  
end

---

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [December 27, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/is-there-a-maximum-size-for-the-receive-in-a-tcpsocket-as-in-str-streamsock-recv-64000/124338/2 "2007-12-27T20:05:46Z")

</div>

On Dec 27, 12:29 pm, Victor R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> printed to the screen for testing.  
> input = session.gets  
> streamSock = TCPSocket.new( srvr, port )  
> streamSock.puts(“#{comm}\n”)  
> str = streamSock.recv( 64000 )  
> puts “Output from Server: #{srvr}”  
> print str  
> puts “\n”  
> streamSock.close  
> end

See my reply to the last thread you posted (in short, use #read rather  
than #recv).

Regards,  
Jordan

---

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [December 27, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/is-there-a-maximum-size-for-the-receive-in-a-tcpsocket-as-in-str-streamsock-recv-64000/124338/3 "2007-12-27T20:17:29Z")

</div>

Hey Jordan, I owe one.  
It works like a charm!

Thanks again,

Victor

---

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [December 27, 2007, 8:30pm UTC](https://www.ruby-forum.com/t/is-there-a-maximum-size-for-the-receive-in-a-tcpsocket-as-in-str-streamsock-recv-64000/124338/4 "2007-12-27T20:30:57Z")

</div>

On Dec 27, 1:17 pm, Victor R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > When this happens the server side fails with a \*`write`: broken  
> > > port = 19557
> 
> > > end
> 
> > See my reply to the last thread you posted (in short, use #read rather  
> > than #recv).
> 
> > Regards,  
> > Jordan

Glad to be of some help! I’ve received enough help from the group – I  
guess it’s about time to give some back. 😉

Regards,  
Jordan
