----------------------------------- Clayton Wed Jan 10, 2007 11:36 pm Networking in Ruby ----------------------------------- All right all you Rubidium folk, listen up :D 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. ----------------------------------- ericfourfour Thu Jan 11, 2007 12:34 am RE:Networking in Ruby ----------------------------------- I'd check out [url=http://www.rubycentral.com/book/]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 Thu Jan 11, 2007 9:46 am Re: Networking in Ruby ----------------------------------- 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 TCPServer and TCPSocket bits for now. 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 Thu Jan 11, 2007 1:06 pm 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: p ARGV And here's how it works: 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 Thu Jan 11, 2007 8:56 pm 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.He needs to send information and also receive it, Ruby won't know what to do with the information it receives, right? ;-) I suppose that was not his original question, but it would be a helpful thing to know. ----------------------------------- Clayton Thu Jan 11, 2007 10:48 pm 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 :?) Any ideas on that? Perhaps I should look up the external keyword in Turing. ----------------------------------- ericfourfour Fri Jan 12, 2007 12:34 am 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. :) ----------------------------------- Cervantes Fri Jan 12, 2007 4:02 pm 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. ----------------------------------- Clayton Fri Jan 12, 2007 5:45 pm 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] Fri Jan 12, 2007 6:26 pm 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. 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 Sat Jan 13, 2007 3:58 am 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.