Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6115991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:09:18+00:00 2026-05-23T15:09:18+00:00

The code below aims at making TCP Server and Clients. But when the number

  • 0

The code below aims at making TCP Server and Clients.
But when the number of the client threads is too big(for example: 100 threads), then client receives an “Connection reset by peer” error. I can’t find out the cause of the error, so I need your help.

Server:

#!/usr/bin/env ruby1.9
# -*- coding: utf-8 -*-

require "socket"
crab = TCPServer.new "127.0.0.1", 8087
while browser = crab.accept
  Thread.new browser do | client |
    puts client.gets
    client.puts "hello"
    client.close
  end
end

Client:

#!/usr/bin/env ruby1.9
# -*- coding: utf-8 -*-
require "socket"
threads_arr = []
ARGV[0].to_i.times do    
  t = Thread.new do
    client = TCPSocket.new "127.0.0.1", 8087
    client.puts "hello"
    client.gets
    client.close
  end  
  threads_arr << t
end
threads_arr.each do | t |
  t.join
end

Envrionment:

Mac OS X 10.6.8

ruby 1.8.7p174 / ruby 1.9.2p180

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:09:19+00:00Added an answer on May 23, 2026 at 3:09 pm

    Would this be easier to do in EventMachine? Threading will only scale so far before it starts to cause trouble. EventMachine also handles load better when receiving a large number of connections.

    You may need to check that your accept queue is sufficiently large. The default is something like 5 pending connections and if they can’t be acknowledged quickly enough you might have them dropped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below should print ten results but instead it prints ten test-ite. Why
The code below works fine but, in the textbox the decimal value has this
The code below does what I need it to do, but it looks like
The code below displays a thumbnail of each image in a specific server directory
My code below is not working on IE8 but work perfectly at FF. I
The code below works exactly as I want it to in my perl script.
The code below obviously searches a directory for Files that contain the word FINAL
The code below is supposed to initiate CSS based on if($row[datesubmitted] > $livetime){ .
The code below makes complete sense to me - its about adding an element
The code below is straight out of the 3.x examples. Can anyone help me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.