Clients <--> Server Communication (Sockets?)
-
I've heard that it is best to use i386-mswin32 Ruby with Windows Sketchup, perhaps because it is compiled with MS Visual Studio.
You can download precompiled i386-mswin32 "Standard" Ruby in zip format, and unzip it to whatever folder you wish (without using an installer, and so not cluttering your Registry.)
ftp://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/Also you can use the pik utility on PC, or RVM utility on Mac, to install (in a gemlike manner,) any and multiple versions of Ruby.
-
Jim, that's Interesting. At first I couldn't replicate your require 'socket' result but then I tried in Sketchup 8 and it worked. "RUBY_VERSION" in SU7 says "1.8.0" and in SU8 "1.8.6" Is that why it doesn't work in 7? I have 1.9.2, 1.8.7, and 1.8.6 all one-click installed and unmodified.
I'm excited to trying to play with the ruby socket.so. Is there any reason to think that my goals to create a bi-directional client/server communication link will NOT be possible with ruby sockets?
Dan, most of what you said when straight over my head. i386-mingW32 vs i386-mswin32 is beyond me at the moment. I can say however, that I use your !loadpaths.rb which adds the i386-mswin32 directory to the $LOAD_PATH and when I "require 'C:/ruby186/lib/ruby/1.8/i386-mingw32/socket'" it returns true. I have not modified any files. Are you recommending that I uninstall my current ruby build and get the mswin32 version? Should I stick with 1.8.6?
Thanks again.
-
@mtalbott said:
Dan, most of what you said when straight over my head.
I replied in the !loadpaths.rb topic, so as not to clutter this one up.
http://forums.sketchucation.com/viewtopic.php?f=180&t=29412&p=297191#p297191 -
Back on topic: Ruby Sockets
@mtalbott said:
I'm excited to trying to play with the ruby socket.so. Is there any reason to think that my goals to create a bi-directional client/server communication link will NOT be possible with ruby sockets?
do a search on the Ruby Forum:
http://www.ruby-forum.com/ -
It's been awhile. Sorry for the slow-to-update response. I wish I had more time to play/work on this stuff. I just wanted to give an update on my progress. After trying several different methods, the method I am using for bi-direction communication between sketchup sessions is using the socket.so ruby library. I've created a udp client program for sketchup that can connect to a ruby console server application. Multiple sketchup sessions can connect to the server and connected clients are managed in a client list by the server. Data can be transmitted from a sketchup session to the server and them broadcasted to all connected clients. As a test, I transmit the view location continuously so every session knows where my the viewpoints are of the other sessions. It works! I'm sure it's inefficient and sloppy but at least it works and doesn't seem to have significant impact on modeling performance.
My next steps (and probably I'll start a new thread if I have questions) are figuring out the best way to thread it so the server can run independent to the sketchup loop. Right now I am using the UI.start_timer to check for new messages every 1/10th of a second. Now that the timer accepts durations less than 1 second this is working well in sketchup 8 but probably wont in 7 and earlier.
The big elephant in front of me is non persistent entity_ids. I knew this going into it but figured I'd work around it. I think it's time to once and for all create a work around for entity identification and lookup. Without going deepb into it, I plan on creating and updating a hash table that will link entities to an id stored in an attrib dictionary that is persistent. I want to figure that out independent to my project because I know there are others frustrated with entity memory and could benefit from a working solution.
That's it. I'm one step closer to sketchup as a multiplayer video game platform. only several thousands more to go.
-
So did you get the
$LOAD_PATH
issue all straightened out ? -
I never really did figure it out completely. right now I'm using a dumbed down version of your !loadpath.rb it looks like this:
begin # add the standard lib path $LOAD_PATH << "C;/Ruby186/lib/ruby/site_ruby/1.8" $LOAD_PATH << "C;/Ruby186/lib/ruby/site_ruby/1.8/i386-msvcrt" $LOAD_PATH << "C;/Ruby186/lib/ruby/site_ruby" $LOAD_PATH << "C;/Ruby186/lib/ruby/1.8" $LOAD_PATH << "C;/Ruby186/lib/ruby/1.8/i386-mingw32" $LOAD_PATH << "C;/Ruby186/lib/ruby/gems/1.8/gems/cool.io-1.0.0/lib" $LOAD_PATH << "C;/Ruby186/lib/ruby/gems/1.8/gems/eventmachine-0.12.10/lib" $LOAD_PATH << "C;/Ruby186/lib/ruby/gems/1.8/gems/iobuffer-1.0.0/lib" $LOAD_PATH << "C;/Ruby186/lib/ruby/gems/1.8/gems/rdiscount-1.6.5/lib" $LOAD_PATH << "." $LOAD_PATH.uniq! # # print LOAD PATHS to console # (May not print during Sketchup startup!) Sketchup.send_action('showRubyPanel;') UI.start_timer(1,false) { puts "\nLOAD PATHS;\n" $LOAD_PATH.each {|x| puts "#{x}\n"} puts "\n\n" } end
As you can see, I pretty much just load in the entire phone book. Works fine for sketchup 8 but not at all for sketchup 7. While I'm sure I can modify something to get it working in 7, at the moment I am relying on a UI.start_timer set to less than one so I think I'm stuck with 8 only anyway.
also, as you can see I tried to play with some ruby gems but never had any success getting them to work in sketchup.
At the end of the day I want to be able to distribute this plugin to other people. I hope I'm not relying too much on the full ruby install.
-
also, the whole mswin32 vs mingw32. I tried to use mswin32 but without a one click installer I think getting it installed correctly with rubygems loaded had me stumped. I got into ruby through sketchup so the whole "full" ruby stuff is new to me. The gem thing was a real issue when I was trying to figure this out. However, now that I've decided to not use any gems, maybe I'll look back into getting the ruby install to be mswin32.
The problem for another day is that the only thing I'm using from ruby 1.8.6 is socket.so but it much have ties to other ruby resources so if i try to directly use it, it's a no go. In the end, I need to figure out how to package up the resources I want to utilize without having to make every user install the full ruby.
-
@mtalbott said:
also, the whole mswin32 vs mingw32. I tried to use mswin32 but without a one click installer I think getting it installed correctly with rubygems loaded had me stumped. ...
One-Click Windows Full Ruby version 1.8.6-p287, the version & patchlevel of Ruby, that matches the interpreter that Google distro'd with Sketchup 8.x
@mtalbott said:
In the end, I need to figure out how to package up the resources I want to utilize without having to make every user install the full ruby.
It's easier to point your users to the above installer, and have them install everything. They "could" install it beneath the Sketchup folder if they wished to keep it separate from their "system" Ruby install. (Which is what I myself do.)
@mtalbott said:
Works fine for sketchup 8 but not at all for sketchup 7. While I'm sure I can modify something to get it working in 7 ...
One of the tricks for SU 7 (on Windows,) is to get users to replace the interpreter DLL that Google distro'd (v1.8.0 which is obsolete anyway,) with the same one distro'd with SU 8.
I posted instructions here:
Ruby Interpreter DLLs (Win32)
.. along with the DLLs (if they didn't have SU 8 installed.) Otherwise they can just copy the DLL from the SU 8 program folder, into the SU 7 program folder. (A drawback is that many scripts are written poorly and "crap out" under v1.8.6-p287, until they are edited, such as wrapping argument lists in parenthesis.)As far as timing goes.. you may be able to "fake" a
UI.start_timer
functionality for SU 7, by using awhile
loop, and callTime.now
which returns fractional seconds. You'll have to play around with it.
~ -
@mtalbott said:
The gem thing was a real issue when I was trying to figure this out.
I posted some links to gem documents that may help. (One of the issues is that it uses Environment Variables, that need to be set correctly thru the Ruby
ENV
hash.)See: SketchUp-Ruby Resources under TECHNICAL REFERENCES for the Rubygems docs.
Several people have tried to get Sketchup Ruby to work with gems, but have not solved the issues yet.
-
@unknownuser said:
(http://groups.google.com/group/sketchupruby/browse_thread/thread/83b98d1de240ba80/a050fc757033ba14#a050fc757033ba14) at Google Sketchup Developers Group":fst84r3p]> I am trying to require 'socket' in a SU script with Mac OS X.
I have tried literal paths.
I have tried $LOAD_PATH<<"Literal Value Here"
....See this post in THIS topic: http://forums.sketchucation.com/viewtopic.php?f=180&t=33759#p297087
Be sure that RUBY_PLATFORM is the same in both Sketchup Ruby and in the OEM Ruby installed by Apple.
(If NOT, COPY, not rename, the entire OEM platform subdir, to a dir named to the RUBY_PLATFORM value within Sketchup Ruby.)
You could try this for trouble shooting:
<span class="syntaxdefault"></span><span class="syntaxcomment">#<br /># global constant RUBY_ENGINE is available in Ruby 1.9 and up <br /></span><span class="syntaxdefault">Object</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">const_set</span><span class="syntaxkeyword">(;</span><span class="syntaxdefault">RUBY_ENGINE</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">RUBY_VERSION</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'.'</span><span class="syntaxkeyword">)[</span><span class="syntaxdefault">0..1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'.'</span><span class="syntaxkeyword">))</span><span class="syntaxdefault"> if RUBY_VERSION</span><span class="syntaxkeyword"><</span><span class="syntaxstring">'1.9.0'</span><span class="syntaxdefault"> <br /></span><span class="syntaxcomment"># <br /></span><span class="syntaxdefault">if RUBY_PLATFORM</span><span class="syntaxkeyword">.include?(</span><span class="syntaxstring">'darwin'</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> $LOAD_PATH</span><span class="syntaxkeyword"><<</span><span class="syntaxstring">"/usr/lib/ruby/#{RUBY_ENGINE}"</span><span class="syntaxdefault"> <br /> $LOAD_PATH</span><span class="syntaxkeyword"><<</span><span class="syntaxdefault">$LOAD_PATH</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">last</span><span class="syntaxkeyword">+</span><span class="syntaxstring">"/#{RUBY_PLATFORM}"<br /></span><span class="syntaxdefault">elsif RUBY_PLATFORM </span><span class="syntaxkeyword">=~ /(</span><span class="syntaxdefault">mswin</span><span class="syntaxkeyword">|</span><span class="syntaxdefault">mingw</span><span class="syntaxkeyword">)/<br /></span><span class="syntaxdefault"> $LOAD_PATH</span><span class="syntaxkeyword"><<</span><span class="syntaxstring">"C;/ruby#{RUBY_VERSION.to_s.split('.').join}/lib/ruby/#{RUBY_ENGINE}"</span><span class="syntaxdefault"> <br /> $LOAD_PATH</span><span class="syntaxkeyword"><<</span><span class="syntaxdefault">$LOAD_PATH</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">last</span><span class="syntaxkeyword">+</span><span class="syntaxstring">"/#{RUBY_PLATFORM}"<br /></span><span class="syntaxkeyword">else<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># unknown platform<br /></span><span class="syntaxdefault">end<br /></span><span class="syntaxcomment"># <br /></span><span class="syntaxdefault">$LOAD_PATH</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">uniq</span><span class="syntaxkeyword">!</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># delete duplicate entries<br />#<br /></span><span class="syntaxdefault">begin <br /> Kernel</span><span class="syntaxkeyword">.require(</span><span class="syntaxstring">'socket'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># use original require method <br /></span><span class="syntaxdefault">rescue LoadError </span><span class="syntaxkeyword">=></span><span class="syntaxdefault"> e <br /> if e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">message</span><span class="syntaxkeyword">.include?(</span><span class="syntaxstring">'no such file to load'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> <br /> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"The file 'socket' could not be found!\nCheck your $LOAD_PATH array.\n"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> <br /> end <br /> stderr</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">write</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">message</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> <br />rescue <br /> raise </span><span class="syntaxcomment"># pass up any other Exceptions <br /></span><span class="syntaxdefault">else <br /> if Object</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">const_defined</span><span class="syntaxkeyword">?(;</span><span class="syntaxdefault">Socket</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> <br /> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"The file 'socket' was loaded.\nThe Socket class has been defined.\n"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> <br /> end <br />end<br /></span><span class="syntaxcomment"># </span><span class="syntaxdefault"></span>
-
Has the situation improved in SketchUp 2014?
I have tried opening a TCP socket:>>require 'socket' true >>hostname = 'localhost' localhost >>port = 6300 6300 >>s = TCPSocket.open(hostname, port) Error; #<Errno;;EACCES; Permission denied - connect(2)> <main>;in `initialize' <main>;in `open' <main>;in `<main>' -e;1;in `eval' nil
Is there a way to get it working in SU2014?
-
It works in standalone Ruby?
Got a sample with server/client that respond to the socket? -
Do you have a firewall active ? (The "permission denied" seems to indicate so.)
If so, can you create an exclusion for Sketchup.exe ?
-
When I first try it under Win7 (with Comodo,) the error message is:
Error: #<Errno::ECONNREFUSED: No connection could be made because the target machine actively refused it. - connect(2)>
-
@dan rathbun said:
When I first try it under Win7 (with Comodo,) the error message is:
Error: #<Errno::ECONNREFUSED: No connection could be made because the target machine actively refused it. - connect(2)>
I disabled Anti-Virus, Sandboxing and Firewall and still get same error.
Perhaps we cannot use "localhost" as a server ?
Maybe need to start a virtual server, WEBrick or something ?
Advertisement