TCP Socket Programming

Discussion in 'Ruby' started by Mac Man, Sep 6, 2008.

  1. Mac Man

    Mac Man Guest

    Hi

    I am trying to establish communication between 2 applications.
    On executing the below piece of code on client side application, I get
    this error

    socket_client.rb:3:in `initialize': Bad file descriptor - connect(2)
    (Errno::EBADF) from socket_client.rb:3:in `new'

    #########
    code:
    #########

    require 'socket'

    client_side = TCPSocket.new('localhost',1045)
    puts "Enter some text: "
    text=gets()




    Server side code works fine and is implemented as displayed below.
    require 'socket'

    ###########
    code:
    ###########

    server_side=TCPServer.new('localhost','1025')
    port = server_side.accept
    data = port.recvfrom(256)[0]
    puts data


    Any suggestions on what could be the possible problem?
    PLease Help

    Macman
    --
    Posted via http://www.ruby-forum.com/.
     
    Mac Man, Sep 6, 2008
    #1
    1. Advertising

  2. Mac Man

    Mac Man Guest

    sorry...that was a mistake..typo error.
    both client and server are pointing to the same port 1045.

    Actually the code goes this way...

    client_side = TCPSocket.new('localhost','1045')
    print "Enter some text: "
    text=gets()
    client_side.write(text)

    I am writing the input text to the server side.

    An issue I found was that this error occurs only in version 1.8.6.
    I tried the same code on version 1.8.1 and it worked, but got a
    different error as below.

    in 'recvfrom' : getnameinfo: ai_family not supported. (SocketError)

    --
    Posted via http://www.ruby-forum.com/.
     
    Mac Man, Sep 6, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mohammed Smadi

    tcp socket programming

    Mohammed Smadi, Oct 4, 2005, in forum: Python
    Replies:
    1
    Views:
    315
    Irmen de Jong
    Oct 4, 2005
  2. Mohammed Smadi

    Re: tcp socket programming

    Mohammed Smadi, Oct 4, 2005, in forum: Python
    Replies:
    0
    Views:
    431
    Mohammed Smadi
    Oct 4, 2005
  3. Tiger
    Replies:
    5
    Views:
    975
    Dave Thompson
    May 1, 2006
  4. Laszlo Nagy
    Replies:
    1
    Views:
    4,861
    Mark Wooding
    Jan 27, 2009
  5. Martin Ambuhl

    Re: TCP Socket Programming

    Martin Ambuhl, Apr 18, 2011, in forum: C Programming
    Replies:
    2
    Views:
    373
    Bill Cunningham
    Apr 22, 2011
Loading...

Share This Page