Clients <--> Server Communication (Sockets?)
-
My current project consists of a need to have bi-directional communication between a server and a handful of clients running sketchup. The idea is to be able to share model information in real-time between multiple sketchup sessions on multiple computers. The data will be simple but often. I'm looking for multi-player computer-game-like performance. The communication would be happening while the user is working in the sketchup file so it is critical to keep the performance hit to the model environment to a minimum.
I've been researching several different methods to accomplish this but don't which one is best:
Web Dialogs:
-
The first thought was to use webdialogs with some sort of AJAX/comet to long poll the server that stores info with php + mysql. However, this seems inefficient. I could be wrong.
-
bi-directional web got me thinking Websockets with HTML5. Alas, IE does not support it so that's a no-go. (wish sketchup could use chrome)
Extension library:
-
So then I bought a book on programming multiplayer games (copyright 2004 so it's old). The go through writing a network library in C++ that use sockets to communicate through UDP or TCP with a server. I was thinking that I could modify it to be a ruby extension library to use native within sketchup. Unfortunately, this is probably a lot harder then I think, if not impossible, as I do not know C++.
-
Then I looked for other pre-made network libraries. There are a few, however, I'm still unclear how I could get any of them to talk to sketchup.
All Ruby:
-
I see that there is an undocumented SKsocket class built into sketchup but I hear that's pretty unreliable.
-
Finally, full ruby has a socket.so that looked promising but I can't seem to load/require it in sketchup without getting a error "127: The specified procedure could not be found."
I'm frustrated that no one solution has jumped out. Any guidance to how you would approach the problem would be much appreciated.
Thanks,
Mike Talbott -
-
Is it cross-platform, or Windows only ?
If Win only, look into Daniel Berger's Win Utilities (they are like the old Win32API.so on steroids.) The server and each client will have to have the suite installed.
http://rubyforge.org/projects/win32utils/
The project forum might be a place to ask this question again, but be sure you tell them the clients are running embedded Ruby under Sketchup.
http://rubyforge.org/forum/forum.php?forum_id=319 -
I think I'd avoid webdialogs for the communication - as it'd just add another layer where thing could go wrong, and via yet another interpreted language. Also, remember that under OSX the WebDialog -> SketchUp bridge is async and can drop messages if they are too close to each other.
-
Thanks Dan and Thomthom,
I 'm going to take both of your advice. I'll look into Win32Utils and I'll stay away from Webdialogs. Is the SKsocket thing not worth exploring at all?
Dan, while cross-platform support would be nice, I'll take what I can get. Windows only is ok.
I'll report back if I figure anything out.
-
But it just might... This on SketchUp 7.
-
You could use socket.so from the Ruby 1.8.6. No idea if the same technique works on Macs.
-
Jim.. noticed that you have the mingW32 compiled full Ruby... but the distro'd interpreter with SU is compiled with VS, ie platform: i386-mswin32, is this an issue, or did you replace the DLL that Sketchup loads with the one from your i386-mingw32 folder ?
And a note to Mike, you'd need to get the RUBY_PLATFORM constant value, and insert it into any path that you either use directly, or append to the $LOAD_PATH array.
-
@dan rathbun said:
is this an issue, or did you replace the DLL that Sketchup loads with the one from your i386-mingw32 folder ?
Neither Ruby nor SketchUp have been modified - both are "typical", unmodified installs.
-
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?
Advertisement