# Questions about TCPSocket

**URL:** <https://www.ruby-forum.com/t/questions-about-tcpsocket/120382>\
**Category:** Ruby\
**Created:** [November 16, 2007, 11:52am UTC](https://www.ruby-forum.com/t/questions-about-tcpsocket/120382 "2007-11-16T11:52:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axel\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7c8e57/32.png) [@Axel\_E](https://www.ruby-forum.com/u/Axel_E)\
**Post date:** [November 16, 2007, 11:52am UTC](https://www.ruby-forum.com/t/questions-about-tcpsocket/120382/1 "2007-11-16T11:52:25Z")

</div>

Dear all,

I am trying to use Ruby bindings of a software that does  
computations by exchanging messages between competent code.  
The details are explained here:

> **[Communication model of OpenXM](http://www.math.kobe-u.ac.jp/OpenXM/1.2.1/html/OpenXM-en/OpenXM/node5.html)**
>
> Communication model of OpenXM

This software can be used from the command line and there, it works as  
expected.  
Now, I’d like to use it from ruby. There are ruby binding scripts.  
However, I encounter some problems when initialising  
TCPSocket - I can’t get any connection. Both ruby and OpenXM are  
installed on the same computer.  
What could be the problem ?

Thank you very much,

Best regards,

Axel

require “socket”  
  
  
class OXSession  
def initialize(host = “localhost”,  
controlport = rand(20000)+1024,  
dataport = controlport+1,  
byteorder = 0)  
@serial = 0  
begin  
printf(“Connecting to %s, \n”, host)  
printf(“Trying to connect to controlport %d, \n”, controlport)  
@controlp = TCPSocket.new(host, controlport)  
sleep 2  
printf(“Trying to connect to dataport %d, \n”, dataport)  
@datap = TCPSocket.new(host, dataport)  
sleep 2  
rescue  
p ‘could not connect’  
end

```
# byte oder negotiation
@byteorder = decide_byte_order(byteorder)

```

end

attr\_accessor :controlp, :datap

def decide\_byte\_order(b\_or\_l)  
if b\_or\_l == 0  
@controlp.read(1)  
@datap.read(1)  
@controlp.flush  
@datap.flush  
@controlp.write(0)  
@datap.write(0)  
return 0  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![Axel\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7c8e57/32.png) [@Axel\_E](https://www.ruby-forum.com/u/Axel_E)\
**Post date:** [November 16, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/questions-about-tcpsocket/120382/2 "2007-11-16T16:06:22Z")

</div>

2007/11/16, Axel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Now, I’d like to use it from ruby. There are ruby binding scripts.  
> However, I encounter some problems when initialising  
> TCPSocket - I can’t get any connection. Both ruby and OpenXM are  
> installed on the same computer.  
> What could be the problem ?

Posting an exception with stack trace often goes a long way to help  
people help you. So I suggest you give that detail.

Generic answer would be: configuration issue, firewall, network  
issues…

Cheers

robert

---

<div class="post-metadata">

**Author:** ![Axel\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7c8e57/32.png) [@Axel\_E](https://www.ruby-forum.com/u/Axel_E)\
**Post date:** [November 16, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/questions-about-tcpsocket/120382/3 "2007-11-16T17:44:53Z")

</div>

-------- Original-Nachricht --------

> Datum: Sat, 17 Nov 2007 00:05:11 +0900  
> Von: “Robert K.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: Re: Questions about TCPSocket

> > This software can be used from the command line and there, it works as  
> > Generic answer would be: configuration issue, firewall, network issues…
> 
> Cheers
> 
> robert
> 
> –  
> use.inject do |as, often| as.you\_can - without end

Dear Robert,

thanks for your reply.  
I now get

dhcppc0:/usr/local/openxm-head/OpenXM/src/ruby # ruby ox.rb  
Connecting to localhost,  
Trying to connect to controlport 1200,  
Exception: Errno::ECONNREFUSED: Connection refused - connect(2)  
ox.rb:172:in `initialize' ox.rb:172:in `new’  
ox.rb:172:in `initialize' ox.rb:315:in `new’  
ox.rb:315

I tried to find some help in previous discussions, and was able to  
identify some open ports, through which I can communicate.  
Is there a way to change what ports are blocked from ruby, as root, on  
Linux ?

Thank you very much,

Axel

---

<div class="post-metadata">

**Author:** ![Axel\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7c8e57/32.png) [@Axel\_E](https://www.ruby-forum.com/u/Axel_E)\
**Post date:** [November 17, 2007, 8:45am UTC](https://www.ruby-forum.com/t/questions-about-tcpsocket/120382/4 "2007-11-17T08:45:49Z")

</div>

2007/11/16, Axel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > I am trying to use Ruby bindings of a software that does  
> > > TCPSocket - I can’t get any connection. Both ruby and OpenXM are  
> > > robert  
> > > dhcppc0:/usr/local/openxm-head/OpenXM/src/ruby # ruby ox.rb  
> > > identify some open ports, through which I can communicate.  
> > > Is there a way to change what ports are blocked from ruby, as root, on Linux ?

Either there is nothing listening on that port or the firewall of your  
or the target machine blocks the connection. If you are on Linux you  
can most likely check with iptables or ip6tables. Chances are that  
there is also a GUI tool for that.

Cheers

robert
