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 5955125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:04:09+00:00 2026-05-22T18:04:09+00:00

Okay, so I have a really simple GServer server and an even simpler TCPSocket

  • 0

Okay, so I have a really simple GServer server and an even simpler TCPSocket client (I looked into writing my own async TCPServer, but that turned out to be bigger shoes than I can fill at the moment, so I stumbled across the wonderul GServer).

Now I have this code in my server.rb:

require 'gserver'
class PServer < GServer
  def initialize
    super(9998)
  end

  def serve client_msg
    for byte in client_msg.bytes
      print byte.chr #Just playing, heh
    end
    print "\n"
    client_msg.print 'Lala'
  end
end

s = PServer.new
s.audit = true
s.debug = true
s.start
s.join

So, when I run it, I get no problems (I think) and get this output:

[Date and stuff, too long to type] PServer 127.0.0.1:9998 start

The client.rb code:

require 'socket'
client = TCPSocket.new('localhost', 9998)
client.print "Hi!"
p client.gets
client.close

Now, when I run the client, the server reports that it connected, the “Hi!” message. The client ‘floats’ open (sorry for the lack of a better expression) the whole time, leaving the connection open (however “Lala” is not printed out).

When I run the client again, omitting the line p client.gets; the server reports a connection, the “Hi!” and the disconnection of the client. The client just executes and I am returned to the good old prompt. Now, I’m wondering why this is happening. Is it the GServer, the Client, am I doing something dreadfully wrong? Please tell meee. I’m in a metaphorical agony right now.

Thanks for even reading this gigantic text (which is probably full of typos).
xo

  • 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-22T18:04:10+00:00Added an answer on May 22, 2026 at 6:04 pm

    I think you have the wrong idea about what the parameter to serve is. It’s not a message, it is an IO object. Calling bytes on the IO object will try to read it until there is nothing left to read (that is, until the connection is closed). You should use gets for line-based communication, or read for binary protocols.

    Try replacing your serve method with this one:

    def serve(socket)
      puts socket.gets.chomp
      socket.puts 'Lala'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, this should be really simple, but I have searched all over for the
Okay, I feel like I am missing something really simple here. I have an
Okay, I'm probably missing something really simple here, but I've been at this for
Okay, so I have this Silverlight client program. I'm not allowed to use the
Okay I have this RewriteRule which is supposed to redirect any request for the
Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay I have a series of objects based on a base class which are
okay i have found the way to run a video in a image.... the
Okay I have updated my code quite a bit. I am getting a new
Okay I have updated my code a little, but I am still not exactly

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.