Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Networking in Ruby
Index -> Programming, Ruby -> Ruby Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Clayton




PostPosted: Wed Jan 10, 2007 11:36 pm   Post subject: Networking in Ruby

All right all you Rubidium folk, listen up Very Happy

Basically I am going to suffer another semester of Turing (doing OOP no less), however, to spice up the final project for the class, I wanted to do some sort of network game and possibly earn some bonus marks by using a different language (well, actually, Turing's Net. module is just too damn slow). So, could you please point me to some beginner's/intermediate level tutorials on networking in Ruby, or post here showing some examples? (We can talk in the IRC room too)

Another thing, I know it is possible to execute the scripts from Turing, but is there a way to pass said script an argument(s) and have it execute (ie sending data over the network)? Will it do this at acceptable speeds?

Thanks in advance for any who help.
Sponsor
Sponsor
Sponsor
sponsor
ericfourfour




PostPosted: Thu Jan 11, 2007 12:34 am   Post subject: RE:Networking in Ruby

I'd check out Programming Ruby: The Pragmatic Programmer's Guide.

Turing again? That sucks. Judging by how boring my Java class is, I couldn't imagine how boring Turing would be.
rdrake




PostPosted: Thu Jan 11, 2007 9:46 am   Post subject: Re: Networking in Ruby

Freakman @ Wed Jan 10, 2007 11:36 pm wrote:
Basically I am going to suffer another semester of Turing (doing OOP no less), however, to spice up the final project for the class, I wanted to do some sort of network game and possibly earn some bonus marks by using a different language (well, actually, Turing's Net. module is just too damn slow). So, could you please point me to some beginner's/intermediate level tutorials on networking in Ruby, or post here showing some examples? (We can talk in the IRC room too)
As stated above, the Pickaxe is a Godly resource. I have a copy, expensive though. Though registration is required, I found this article to be quite helpful explaining it as well. Don't worry too much about the other stuff, concentrate on the TCPServer and TCPSocket bits for now.

Freakman @ Wed Jan 10, 2007 11:36 pm wrote:
Another thing, I know it is possible to execute the scripts from Turing, but is there a way to pass said script an argument(s) and have it execute (ie sending data over the network)? Will it do this at acceptable speeds?
Only thing I can think of to pass arguments to Turing would be to send the information to a file which Turing would then read. Though I'm seeing nightmares right now of both trying to access the file at the same time.... As for speed, don't look for too much. Piping the output of a program to another instead of sharing via a file is much faster I can tell you that. I have not tried what you are attempting myself.

Edit: Damn typos.
Cervantes




PostPosted: Thu Jan 11, 2007 1:06 pm   Post subject: Re: Networking in Ruby

rdrake, I think you misunderstood his question. He's not looking to give his Turing program arguments, but rather get his Turing program to call a Ruby program that takes arguments. Of course this is possible. You just use Sys.Exec in turing to give a command. Now you just need to learn how to use arguments in a ruby program. The easiest way to do this is to use ARGV.
Here's a program I made called test.rb:
code:

p ARGV


And here's how it works:
code:

geoff@trademeet:~/Desktop$ ruby test.rb
[]
geoff@trademeet:~/Desktop$ ruby test.rb --foo
["--foo"]
geoff@trademeet:~/Desktop$ ruby test.rb arg1 arg2
["arg1", "arg2"]


It's that easy. The args you give your program are stored in an array called ARGV.
rdrake




PostPosted: Thu Jan 11, 2007 8:56 pm   Post subject: Re: Networking in Ruby

Cervantes @ Thu Jan 11, 2007 1:06 pm wrote:
rdrake, I think you misunderstood his question. He's not looking to give his Turing program arguments, but rather get his Turing program to call a Ruby program that takes arguments.
He needs to send information and also receive it, Ruby won't know what to do with the information it receives, right? Wink

I suppose that was not his original question, but it would be a helpful thing to know.
Clayton




PostPosted: Thu Jan 11, 2007 10:48 pm   Post subject: Re: Networking in Ruby

Cervantes, that looks like what I need, however, I also have to be able to send information back to the Turing program so that it can process it (I really wish I could just do my final project in Ruby entirely Confused) Any ideas on that? Perhaps I should look up the external keyword in Turing.
ericfourfour




PostPosted: Fri Jan 12, 2007 12:34 am   Post subject: RE:Networking in Ruby

You won't get anywhere with external. It only works with functions compiled with Turing. There are a few commands in Turing that deal with arguments but I guess this won't work with source code.

It seems getting information to Ruby is the easy part. Getting information to Turing is the hard part. I'm excited to see what you come up with. Smile
Cervantes




PostPosted: Fri Jan 12, 2007 4:02 pm   Post subject: RE:Networking in Ruby

Check out the menus in the Turing IDE. Probably the Run menu. This can be done, I'm pretty sure. It might require you to compile the Turing program, though.

If not, you can always just have Ruby write the data you need to a file, then have Turing read that.
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Fri Jan 12, 2007 5:45 pm   Post subject: Re: Networking in Ruby

then comes the problem of figuring out how long the data will take to be written to a file. I suppose you could mickey-mouse a loop checking for the file to exist before trying to open it, but that isn't very efficient...
[Gandalf]




PostPosted: Fri Jan 12, 2007 6:26 pm   Post subject: RE:Networking in Ruby

Hmm, external is a bit interesting. IIRC it works by accessing certain points in memory and executing the instructions stored there. If this were true, which it most likely isn't, it would be theoretically possible to directly access the variables of another running program. Theoretically.

Cervantes wrote:
If not, you can always just have Ruby write the data you need to a file, then have Turing read that.

This would probably work pretty well if you're just accessing the file from Turing, but if you try to do it both ways... Nightmare, like rdrake said. I tried this a while ago with my chess program, in order to use an AI programmed in a faster language through text commands, I must say it didn't turn out well.
ericfourfour




PostPosted: Sat Jan 13, 2007 3:58 am   Post subject: RE:Networking in Ruby

Or you can use the Net module and wait for a single bit of information that tells it the file is ready.
Display posts from previous:   
   Index -> Programming, Ruby -> Ruby Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: