Clients <--> Server Communication (Sockets?)

Clients <--> Server Communication (Sockets?)

Postby mtalbott » Mon Dec 27, 2010 11:34 pm

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:

1. 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.

2. 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:

3. 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++.

4. 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:

5. I see that there is an undocumented SKsocket class built into sketchup but I hear that's pretty unreliable.

5. 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
0

mtalbott 
 

Re: Clients <--> Server Communication (Sockets?)

Postby Dan Rathbun » Tue Dec 28, 2010 7:36 am

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
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: Clients <--> Server Communication (Sockets?)

    Postby thomthom » Tue Dec 28, 2010 12:15 pm

    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.
    0
    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund
    User avatar
    thomthom 
    PluginStore Author
    PluginStore Author
     

    Re: Clients <--> Server Communication (Sockets?)

    Postby mtalbott » Wed Dec 29, 2010 12:21 am

    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.
    0

    mtalbott 
     

    Re: Clients <--> Server Communication (Sockets?)

    Postby Jim » Wed Dec 29, 2010 12:35 am

    You could use socket.so from the Ruby 1.8.6. No idea if the same technique works on Macs.

    0986.png
    0
    Last edited by Jim on Wed Dec 29, 2010 12:45 am, edited 2 times in total.
    Hi

    Jim 
    Global Moderator
     

    Re: Clients <--> Server Communication (Sockets?)

    Postby Jim » Wed Dec 29, 2010 12:38 am

    But it just might... This on SketchUp 7.
    0984.png


    0985.png
    0
    Hi

    Jim 
    Global Moderator
     

    Re: Clients <--> Server Communication (Sockets?)

    Postby Dan Rathbun » Wed Dec 29, 2010 1:35 am

    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.
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: Clients <--> Server Communication (Sockets?)

      Postby Jim » Wed Dec 29, 2010 1:39 am

      Dan Rathbun wrote: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.
      0
      Hi

      Jim 
      Global Moderator
       

      Re: Clients <--> Server Communication (Sockets?)

      Postby Dan Rathbun » Wed Dec 29, 2010 3:05 am

      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.
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: Clients <--> Server Communication (Sockets?)

        Postby mtalbott » Wed Dec 29, 2010 3:46 am

        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.
        0

        mtalbott 
         

        Re: Clients <--> Server Communication (Sockets?)

        Postby Dan Rathbun » Wed Dec 29, 2010 2:17 pm

        mtalbott wrote: 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.
        viewtopic.php?f=180&t=29412&p=297191#p297191
        0
          I'm not here much anymore. But a PM will fire email notifications.
          User avatar
          Dan Rathbun 
          PluginStore Author
          PluginStore Author
           

          Re: Clients <--> Server Communication (Sockets?)

          Postby Dan Rathbun » Wed Dec 29, 2010 2:19 pm

          Back on topic: Ruby Sockets
          mtalbott wrote: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/
          0
            I'm not here much anymore. But a PM will fire email notifications.
            User avatar
            Dan Rathbun 
            PluginStore Author
            PluginStore Author
             

            Re: Clients <--> Server Communication (Sockets?)

            Postby Dan Rathbun » Thu Dec 30, 2010 6:18 am

            On Dec 21, 8:16 pm, Lindsey Mysse, in topic External Libraries Mac OS X at Google Sketchup Developers Group wrote:> 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: 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:
            Code: Select all
            #
            # global constant RUBY_ENGINE is available in Ruby 1.9 and up 
            Object.const_set(:RUBY_ENGINE,RUBY_VERSION.split('.')[0..1].join('.')) if RUBY_VERSION<'1.9.0' 

            if RUBY_PLATFORM.include?('darwin')
              $LOAD_PATH<<"/usr/lib/ruby/#{RUBY_ENGINE}" 
              $LOAD_PATH
            <<$LOAD_PATH.last+"/#{RUBY_PLATFORM}"
            elsif RUBY_PLATFORM =~ /(mswin|mingw)/
              $LOAD_PATH<<"C:/ruby#{RUBY_VERSION.to_s.split('.').join}/lib/ruby/#{RUBY_ENGINE}" 
              $LOAD_PATH
            <<$LOAD_PATH.last+"/#{RUBY_PLATFORM}"
            else
              # unknown platform
            end

            $LOAD_PATH.uniq! # delete duplicate entries
            #
            begin 
              Kernel
            .require('socket')  # use original require method 
            rescue LoadError => e 
              if e
            .message.include?('no such file to load') 
                UI
            .messagebox("The file 'socket' could not be found!\nCheck your $LOAD_PATH array.\n") 
              end 
              stderr
            .write(e.message) 
            rescue 
              raise  
            # pass up any other Exceptions 
            else 
              if Object
            .const_defined?(:Socket) 
                UI
            .messagebox("The file 'socket' was loaded.\nThe Socket class has been defined.\n") 
              end 
            end
            #         
            0
            Last edited by Dan Rathbun on Fri Apr 01, 2011 5:02 pm, edited 1 time in total.
              I'm not here much anymore. But a PM will fire email notifications.
              User avatar
              Dan Rathbun 
              PluginStore Author
              PluginStore Author
               

              Re: Clients <--> Server Communication (Sockets?)

              Postby mtalbott » Thu Feb 17, 2011 1:05 am

              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.
              0

              mtalbott 
               

              Re: Clients <--> Server Communication (Sockets?)

              Postby Dan Rathbun » Thu Feb 17, 2011 6:35 am

              So did you get the $LOAD_PATH issue all straightened out ?
              0
                I'm not here much anymore. But a PM will fire email notifications.
                User avatar
                Dan Rathbun 
                PluginStore Author
                PluginStore Author
                 

                Re: Clients <--> Server Communication (Sockets?)

                Postby mtalbott » Fri Feb 18, 2011 12:19 am

                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:
                Code: Select all
                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.
                0

                mtalbott 
                 

                Re: Clients <--> Server Communication (Sockets?)

                Postby mtalbott » Fri Feb 18, 2011 12:32 am

                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.
                0

                mtalbott 
                 

                Re: Clients <--> Server Communication (Sockets?)

                Postby Dan Rathbun » Fri Feb 18, 2011 1:16 am

                mtalbott wrote: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 wrote: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 wrote: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 a while loop, and call Time.now which returns fractional seconds. You'll have to play around with it.
                ~
                0
                  I'm not here much anymore. But a PM will fire email notifications.
                  User avatar
                  Dan Rathbun 
                  PluginStore Author
                  PluginStore Author
                   

                  Re: Clients <--> Server Communication (Sockets?)

                  Postby Dan Rathbun » Fri Feb 18, 2011 1:26 am

                  mtalbott wrote: 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.
                  0
                    I'm not here much anymore. But a PM will fire email notifications.
                    User avatar
                    Dan Rathbun 
                    PluginStore Author
                    PluginStore Author
                     

                    Re: Clients <--> Server Communication (Sockets?)

                    Postby tomasz » Fri Aug 22, 2014 4:48 pm

                    Has the situation improved in SketchUp 2014?
                    I have tried opening a TCP socket:
                    Code: Select all
                    >>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?
                    0

                    tomasz 
                    SU2TH & SU2KT Developer
                     

                    Re: Clients <--> Server Communication (Sockets?)

                    Postby tt_su » Fri Aug 22, 2014 5:51 pm

                    It works in standalone Ruby?
                    Got a sample with server/client that respond to the socket?
                    0
                    User avatar
                    tt_su 
                    SketchUp Team
                    SketchUp Team
                     

                    Re: Clients <--> Server Communication (Sockets?)

                    Postby Dan Rathbun » Fri Aug 22, 2014 9:20 pm

                    Do you have a firewall active ? (The "permission denied" seems to indicate so.)

                    If so, can you create an exclusion for Sketchup.exe ?
                    0
                      I'm not here much anymore. But a PM will fire email notifications.
                      User avatar
                      Dan Rathbun 
                      PluginStore Author
                      PluginStore Author
                       

                      Re: Clients <--> Server Communication (Sockets?)

                      Postby Dan Rathbun » Fri Aug 22, 2014 9:23 pm

                      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)>
                      0
                        I'm not here much anymore. But a PM will fire email notifications.
                        User avatar
                        Dan Rathbun 
                        PluginStore Author
                        PluginStore Author
                         

                        Re: Clients <--> Server Communication (Sockets?)

                        Postby Dan Rathbun » Fri Aug 22, 2014 9:34 pm

                        Dan Rathbun wrote: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 ?
                        0
                          I'm not here much anymore. But a PM will fire email notifications.
                          User avatar
                          Dan Rathbun 
                          PluginStore Author
                          PluginStore Author
                           

                          SketchUcation One-Liner Adverts

                          by Ad Machine » 5 minutes ago



                          Ad Machine 
                          Robot
                           



                           

                          Return to Developers' Forum

                          Who is online

                          Users browsing this forum: No registered users and 8 guests

                          Visit our sponsors: