tags:

views:

43

answers:

3

hi, I would like to establish a connection between 2 computers using socket. For this purpose one of them is a server and this is the code I've write:

sock= TCPServer.open('localhost', 6666)
sock.accept

the client try to establish the connection:

client = TCPSocket.open(ip_server, 6666)

but is not working. I've notice scanning server's ports that the server does not open the port to the network, only works in local mode.

Any suggestion, thk in advance

A: 

Yes, and it allright so, because you said it should bind the server port to the interface of 'localhost' and this is 127.0.0.1 and is bind to your loopback interface and not to any real interface connecting to the realworld.

You should try

sock = TCPServer.new(6666)
sock.accept
jigfox
A: 

It works in "local mode" because it listens on localhost wich is loopback address for the computer the server is launched in. The IP address of your server should be address your computer has on local network (something like 192.168.x.x).

Eimantas
A: 

I've used this code successfully. Server side:

serverSocket = TCPServer.new( "", port )
serverSocket.accept

and on the client

t = TCPSocket.new(server_ip, port.to_i)  

However, recently I've started using the 'EventMachine' gem, which made handling sockets 10 times easier

AShelly