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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:31:39+00:00 2026-05-27T15:31:39+00:00

I have a strange bit of functionality going on when executing the following code

  • 0

I have a strange bit of functionality going on when executing the following code on a Mac and on an Ubuntu installation.

My code makes a connection to my Arduino, which then checks for whether the client is connected (it connects successfully) and I then use Ruby code to send a command to my Arduino via t.puts using the socket gem, which then outputs whatever I send it to the serial output using the Arduino software. That’s the easy part.

When the following is executed on a Mac my serial outputs the following, which is correct:

{power, tv} # t.puts "{power, tv}"

However, when the same code is executed on Ubuntu I get the following in the serial output, as if it’s trying to connect again. It doesn’t give the above serial output that it does on the Mac:

Connecting... # t.puts "{power, tv}" # Connecting... (text is actually coming from Arduino not the below code).

I have double checked that my Arduino, IP, code and port are correct (which is what it’s connecting to). I just don’t see the reason why the output would be different on Mac and Ubuntu.

Any reasons why this would be happening and whether the following code can be modified in such a way that it’s sending it properly on all environments?

#!/usr/bin/ruby

require "socket"

#Thread.new {

  begin
    puts "Connecting to 10.1.1.45..."
    t = TCPSocket.new("10.1.1.45", 80)
  rescue
    puts "error : #{$!}"
  else
    t.print "{power,tv}"
    t.close
    puts "Sent command..."
  end

#}

Keep in mind I can connect to 10.1.1.45 just fine (I can PING, etc) so the actual Arduino code is not at fault here as far as I know, because I’m testing this by plugging it into the Mac and the Ubuntu and executing the exact same code above. Feel free to ask me any further questions and I’ll be happy to answer them in as much detail as possible to help me on my way.

Thanks in advance.

  • 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-27T15:31:40+00:00Added an answer on May 27, 2026 at 3:31 pm

    In ruby puts is just a method on an IOStream object and the object can be changed without you knowing it.

    You might want to try this, to see if it solves your problem:

    begin
      STDOUT.puts "Connecting..."
      t = TCPSocket.new("10.1.1.45", 80)
    rescue
      STDOUT.puts "error : #{$!}"
    else
      t.print "{power,tv}"
      t.close
      STDOUT.puts "Sent command..."
    end
    

    It’s possible that puts was being called on your new socket.

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

Sidebar

Related Questions

Strange Question i guess but i have this bit of code in my page...
I have working code but it seems a bit strange that I have to
I have a bit of a strange problem, please examine the following SQL CREATE
This a bit of strange one.... We have an internal web app that runs
I have a bit of a strange question. Can anyone tell me where to
I have a bit of a strange problem. I am trying to send in-app
Right, bit of a strange question; I have been doing some linq to XML
I have strange problem with sharepoint and ajax functionality. We have an UpdatePanel placed
I have a strange issue: there is a SectionPart with composite, which is create
Lets say I have the following code: public class Collection implements CollectionInterface{ ElementInterface[] elementArray

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.