Skip to content
Arnaud Declercq edited this page Dec 21, 2018 · 6 revisions

Introduction

Sockets are a way to break the boundaries between programs and computer by allowing transfer of data between them.

In this case, for example, sockets are used to transfer data between Grasshopper and Dynamo.

socketsghtodynamo_x264

Note: you can find all the files used to create the examples below [here](NEED NEW LINK).

Try it within one UI

The simplest way to get your grasp on Sockets is to try it within a single UI. This is not really useful but great to wrap your head around it.

Sockets are working as an adapter. So, drop an adapter component on the canvas and select SocketAdapter:

image

You need one adapter to send the information and one to receive it (they would generally be in different programs or computers). The use the regular pull and push components like for any other adapter:

image

Data transfer is not limited to a 1-to-1 connection. You can as easily send data to as many other sockets you want:

bhomsocket_onetomany

You could also use the same socket (i.e. same address and port) to send multiple streams of data as long as you use tags to differentiate them:

image

Alternatively, you can create one socket per flow of data you want to transfer. To do that, create sockets on different port numbers. The port number must be at least 3000. This option has a few benefits: you don't have to use filter queries and tags and transfer is a bit faster since you spread the data between multiple sockets. It is a bit less practical though since you have to work with arbitrary port numbers instead of tags.

image

Transfer data between UIs

Once you get the gist of it, transferring data across programs is not very different to what we have done so far. Here's what it looks like if we extend the previous example to Dynamo:

bhomsocket_accrossprograms

As you can see, it doesn't matter that we still have the receiving sockets in Grasshopper. As we showed earlier, socket adapters are capable of handling 1-to-many transfers and it doesn't matter if the receivers are in the same program or not.

Transfer data between computers

image

Again things will not be massively different here. The only new part is to take care of the IP address of the other computer you want to connect to. To get that information, just open a command window (in start menu, search for "cmd.exe") and type "ipconfig". It will give you a bunch of information, search for a line that say "IPv4 Address". This value is what you will input into the "address" input of the SocketAdapter component of the other computer.

image

Notice that it doesn't matter if the IP address you use is for the computer pulling or pushing. The two computer will have to be on the same network though so don't use sockets to connect computer across offices (for that, use the Mongo_Toolkit). If you are both connected by Wifi and by cable, you will see two Ipv4 addresses as in the case above. It doesn't matter which one you chose but the Ethernet will obviously be faster.