socket level network programming

Discussion in 'Ruby' started by Martin DeMello, Jun 6, 2005.

  1. 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
     
    Martin DeMello, Jun 6, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pabbu
    Replies:
    8
    Views:
    740
    Marc Boyer
    Nov 7, 2005
  2. Kaszeta
    Replies:
    0
    Views:
    349
    Kaszeta
    Oct 4, 2007
  3. Scorpiion
    Replies:
    1
    Views:
    1,369
    Scorpiion
    Dec 25, 2008
  4. Heinrich Wolf
    Replies:
    0
    Views:
    385
    Heinrich Wolf
    Apr 26, 2012
  5. ImpalerCore
    Replies:
    0
    Views:
    387
    ImpalerCore
    Apr 26, 2012
Loading...

Share This Page