if string = "mike" then print "Hi mike"

Discussion in 'Ruby' started by Bigmac Turdsplash, May 6, 2009.

  1. server/client connection
    so, im only a few days into ruby, im working on some tcp and there is a
    problem with my client.rb... if str == ???? this if statement is always
    skipped and im not sure why?

    also, from the server with the gets command i want to send the client a
    string like "mike skateboard boxing" then when the client recives this
    string how can i brake this into 3 arrays or strings?

    #server.rb
    require "socket"
    dts = TCPServer.new('localhost', 1234)
    loop do
    Thread.start(dts.accept) do |s|
    print(s, " is accepted\n")
    #gets, what command to send to the client?
    str = gets
    s.write(str)
    print(s, " is gone\n")
    s.close
    end
    end
    ------------end of server-------------

    #client.rb
    require 'socket'
    while true
    streamSock = TCPSocket.new( "127.0.0.1", 1234 )
    str = streamSock.recv( 100 )
    print str


    if str == 'mike'
    print 'Hi mike'
    elsif str == 'user'
    print 'hi user'
    end
    end

    --------end of client
    --
    Posted via http://www.ruby-forum.com/.
     
    Bigmac Turdsplash, May 6, 2009
    #1
    1. Advertising

  2. Hi,

    At Wed, 6 May 2009 10:43:23 +0900,
    Bigmac Turdsplash wrote in [ruby-talk:335871]:
    > so, im only a few days into ruby, im working on some tcp and there is a
    > problem with my client.rb... if str == ???? this if statement is always
    > skipped and im not sure why?


    #gets method returns a string with a newline if you ended the
    input with enter. You can chomp it or use double Ctrl-D
    instead of enter.

    --
    Nobu Nakada
     
    Nobuyoshi Nakada, May 6, 2009
    #2
    1. Advertising

  3. I've gotten into the habit of using gets.chomp when reading input of
    any kind. It's so easy to forget that newlines are still on there.

    On Tue, May 5, 2009 at 10:56 PM, Nobuyoshi Nakada <> wrot=
    e:
    > Hi,
    >
    > At Wed, 6 May 2009 10:43:23 +0900,
    > Bigmac Turdsplash wrote in [ruby-talk:335871]:
    >> so, im only a few days into ruby, im working on some tcp and there is a
    >> problem with my client.rb... if str =3D=3D ???? this if statement is alw=

    ays
    >> skipped and im not sure why?

    >
    > #gets method returns a string with a newline if you ended the
    > input with enter. =A0You can chomp it or use double Ctrl-D
    > instead of enter.
    >
    > --
    > Nobu Nakada
    >
    >
     
    Michael Morin, May 6, 2009
    #3
  4. Nobuyoshi Nakada wrote:
    > Hi,
    >
    > At Wed, 6 May 2009 10:43:23 +0900,
    > Bigmac Turdsplash wrote in [ruby-talk:335871]:
    >> so, im only a few days into ruby, im working on some tcp and there is a
    >> problem with my client.rb... if str == ???? this if statement is always
    >> skipped and im not sure why?

    >
    > #gets method returns a string with a newline if you ended the
    > input with enter. You can chomp it or use double Ctrl-D
    > instead of enter.


    Oh, wow... a bit confused at first but then i googled ruby chomp and
    then it made sence, when you press enter \n

    if string.chomp == "mike"
    print "hello mike\n"
    system("calc.exe")

    # how can i execute calc.exe and continue with the script well calc is
    still running????

    --
    Posted via http://www.ruby-forum.com/.
     
    Bigmac Turdsplash, May 6, 2009
    #4
  5. Bigmac Turdsplash

    Heesob Park Guest

    Hi,

    2009/5/6 Bigmac Turdsplash <>:
    > Nobuyoshi Nakada wrote:
    >> Hi,
    >>
    >> At Wed, 6 May 2009 10:43:23 +0900,
    >> Bigmac Turdsplash wrote in [ruby-talk:335871]:
    >>> so, im only a few days into ruby, im working on some tcp and there is a
    >>> problem with my client.rb... if str =3D=3D ???? this if statement is al=

    ways
    >>> skipped and im not sure why?

    >>
    >> #gets method returns a string with a newline if you ended the
    >> input with enter. =C2=A0You can chomp it or use double Ctrl-D
    >> instead of enter.

    >
    > Oh, wow... a bit confused at first but then i googled ruby chomp and
    > then it made sence, when you press enter \n
    >
    > if string.chomp =3D=3D "mike"
    > =C2=A0 print "hello mike\n"
    > =C2=A0 system("calc.exe")
    >
    > # how can i execute calc.exe and continue with the script well calc is
    > still running????
    >

    Try
    system("start calc.exe")

    Regards,
    Park Heesob
     
    Heesob Park, May 6, 2009
    #5
    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. fe

    To Mike Treseler only

    fe, Mar 5, 2004, in forum: VHDL
    Replies:
    2
    Views:
    599
    Duane Clark
    Mar 6, 2004
  2. Jim Demetri

    Mike Taylor?

    Jim Demetri, Nov 27, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    417
  3. Ilias Lazaridis
    Replies:
    0
    Views:
    502
    Ilias Lazaridis
    Jan 8, 2005
  4. Robert L.

    Mike: Reply to me by Mail

    Robert L., Aug 2, 2004, in forum: HTML
    Replies:
    1
    Views:
    351
    dimitri
    Aug 4, 2004
  5. Replies:
    0
    Views:
    337
Loading...

Share This Page