socket level network programming

M

Martin DeMello

I'm trying to learn a bit about socket level programming (using ruby, of
course); I'm running into what I'm sure is a simple problem but I'm
stuck.

Here's the code:

#server
require 'socket'

server = TCPServer.new('127.0.0.1', 12345)
while (session = server.accept)
puts "Request length: #{session.gets.length}"
$stdout.flush
session.close
end

-------------------------------------------------

#client
require 'socket'

l = 1000
sock = TCPSocket.new('127.0.0.1', 12345)
packet = "1" * l
sock.send(packet, 0)
sock.close

-------------------------------------------------

Up to a certain length, everything works fine, but over that the server
crashes with a

server.rb:5:in `gets': Invalid argument (Errno::EINVAL)

What's the right way to handle this?

martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top