Clients <--> Server Communication (Sockets?)
-
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