Grasshopper

algorithmic modeling for Rhino

Hi!

I'm an old maxer and pretty new both to Rhino and GH.
I'm trying to send and receive UDP messages to and from GH. I've easily coded a udp sender but my receiver makes Rhino freeze. Luis Fraguada has done it using The Engine from the grasshopper-tools.
- How do I make another "thread" I could have a upd listener waiting for new incoming messages ? How do I avoid these freezes ?

I have the latest possible versions and I'm running on a Mac with Windows XP and WMware.

Thank you !

O

Views: 2509

Replies are closed for this discussion.

Replies to This Discussion

It will freeze no matter what refreshes the canvas. Check out the new timer component...does something similar to Giulio's "the engine." the idea is to do it asynchronously, having one thread waiting for the info. I've been too busy to jump on that at the moment, and actually, though some components (image) work asynch, I am not sure GH script nodes allow it... Perhaps David or Rajaa could answer that.

By the way, is your data feed continuous?
Thanks for your answer!
One of the problem is Giulio's "the engine" does not work with me. I could not figure out why. I guess this is not a version problem since I have the latest ones.

It seems that you cannot use multithreading with VB because you cannot add imports. So impossible to add "Imports System.Threading". I'm not sure it would work anyway.
Here is my super simple code. In case someone seems something wrong.

If onoff Then
Dim rUDPClient As New System.Net.Sockets.UdpClient
rUDPClient = New System.Net.Sockets.UdpClient(11000)
Dim receiveBytes As [Byte]()
Dim RemoteIpEndPoint As System.Net.IPEndPoint = New System.Net.IPEndPoint(System.Net.IPAddress.Any, 1111)

receiveBytes = rUDPClient.Receive(RemoteIpEndPoint)
A = System.Text.Encoding.ASCII.GetString(receiveBytes)
End If

(I know this should go to the VB.net discussion threads but I started to talk about this here.)

Thanks again.
Oops. I had not seen the Giulio Piacentino's patches. It works perfectly!! Many thanks !
You saved me a lot of time...
Hi Oliver, this simple UDP asynchronous listener should help you in this task. It is tested only with Processing (sorry, I don't have Max). It listens to the loopback address, but you can change this. In this case it does not freeze the sketch - it simply drops frames or re-releases old ones if the connection is too slow. It could be re-worked to be used in other scenarios, though.

It uses with the Timer from Grasshopper version GH 0.6.19. I am sending the Processing sketch as well, so you can test it (with Processing version 1.0.5 and Stephane Cousot's UDP library udp.zip from http://processing.org/reference/libraries/ ).

One small remark: this is a listener on the very basic UDP layer. You need to define the way you want your data to be subdivided (which bytes, small or big endian, strings, etc you want to use).
I hope this helps and please let me know more details if you need any further help.
Attachments:
"Perhaps David or Rajaa could answer that."

Or Giulio...coooool! Nicely done.
Wow. Thank you.
Hi Giulio, It works perfectly!! Many thanks ! You saved me a lot of time... Really nice from you for sharing this stuff.
Here is a simple and obvious Max patch to send data to Grasshooper using udp.
Only "mxj net.udp.send" sends proper lists to Grasshooper. "udpsend" does not (small format problem).
Attachments:
Hi Oliver, nice to hear this.

If you want to receive things other than ASCII strings, you could try using methods of the System.BitConverter and System.Convert classes (ToByte, ToDouble, etc.. from Byte[]) instead of System.Text.Encoding.ASCII. Differences in "endianess" can be dealt with System.Net.IPAddress.NetworkToHostOrder(). BitConverter.IsLittleEndian tells what "endinaness" your system has. I never had trouble with this, though, as I used the same tipe of machines on both receiver and sender sides.
Thank you for the info. Indeed, this works fine. Max also has an object that works fine "mxj net.udp.send" with no need of changing your code.
I'm now trying to convert the incoming string as a list of ints for point coordinates. I'll try to figure out how today. ;)
Hi everyone, thanks a lot for the posts and the code! It´s awesome!

I attach Giulio´s script with the Split routine added in order to have several types of data, numerical and textual, streaming at the same time.

In the script the implemented protocol is like:

"data_1::data_2:: ... ::data_N"

So, in your server application you can create the stream using a routine like this :
(using Java sintax)

// the message to send with the first datum
String message = String.valueOf( datum_0 );

// new data added with the separator "::"
message += "::";
message += String.valueOf(datum_1 );

// ... the same until the last one
message += "::";
message += String.valueOf(datum_N );

// Then stream data
udp.send( message, ip, port );

Note we use the String.valueOf() method in order to convert different numeric types to strings and concatenate them to the message string.

I have tried it with processing as you can see in the video. Hope it is useful.

Cheers!
Attachments:
Nice to see it being used! If you want to try a loopback into Processing, see the new UDP receiver+sender here (example with Processing as usual).

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service