Storyboard IO TCP/IP Relay Application for Mobile Platforms

Crank Storyboard Designer samples and code snippets.

Moderator: jamiev

Storyboard IO TCP/IP Relay Application for Mobile Platforms

Postby Evan » Mon Mar 02, 2015 1:47 pm

New to Storyboard 4.0, we've added the GREIO plugin to iOS and improved custom plugin support on mobile platforms. Attached are two sample applications that demonstrate the Storyboard IO TCP/IP functionality talked about in this post for Android and iOS. Review that post to understand the purpose of the TCP/IP connection and look at the C code involved.

As a brief overview, the tcp_client application has a simple button that, when touched, will execute the send_event_outbound Lua function and send a custom 'HelloOutThere' event to the channel 'outbound', which the client is listening on. The client will take that event and pass it on to the server, who will in turn pass it to the channel it is listening on, which should be the tcp_server application channel. The tcp_server application is listening for the 'HelloOutThere' event, and will call the Lua function received_event which will display the event data on the screen.

To have the samples run properly, there are a few things to make sure to do when exporting the application to iOS/Android. Under 'Storyboard Runtime Options' in the export dialog, make sure to set the channel name for the server application (-ogreio,channel=<name>). This should be the same name sent into the call to init_server. When exporting to Android, you need to add the 'android.permission.INTERNET' permission in order to successfully set up the connection, which you can do under 'Advanced Options'. You also need to set the 'Shared Object List Location' to be the path to user_libs.txt, found at the root of the project. This informs the exporter that there are custom libraries to load and tells it where they are. Once the applications are exported properly, make sure to run the server application first or the client won't have anything to connect to.

The samples can be adapted to work on other operating systems as well. For that you will need to re-compile sbio_tcprelay.c into a shared object for whatever environment you are in. I've attached a sample Makefile which you can change to build for your environment. You will need to change the SB_ROOT variable to contain the absolute path to the runtime you want to use. You may also need to change the CC variable to the appropriate compiler, as well as add any OS specific CFLAGS or LDFLAGS necessary.
Attachments
Makefile.txt
Sample makefile for sbio_tcprelay.c
(682 Bytes) Downloaded 801 times
tcp_server.zip
Server application
(90.8 KiB) Downloaded 912 times
tcp_client.zip
Client application
(90.64 KiB) Downloaded 831 times
Evan
 
Posts: 20
Joined: Wed Aug 27, 2014 7:29 am

Re: Storyboard IO TCP/IP Relay Application for Mobile Platfo

Postby Evan » Thu Jul 02, 2015 11:52 am

The post that I referenced above links to code for the TCP/IP relay as a standalone application, but a Lua module is needed for use in the manner described here. Attached is an extension of the original sbio_relay.c that includes the Lua connection required for the examples in this post.
Attachments
sbio_tcprelay.c
The TCP/IP relay as a Lua module
(9.38 KiB) Downloaded 762 times
Evan
 
Posts: 20
Joined: Wed Aug 27, 2014 7:29 am

Re: Storyboard IO TCP/IP Relay Application for Mobile Platfo

Postby atinir » Mon Apr 03, 2017 7:48 am

Hi Evan,

Thank you for this post. i just complied sbio_tcprelay.c. What I get as output is the sbio_tcprelay.o and sbio_tcprelay.so. I don't uderstand should I get an executable file as output? How should I use the object file sbio_tcprelay.o?
The tcp_server will be deployed in Android, and the tcp_client in Linux machine. The previous example in this post I understand that I should use the command line to start both client and server, but in this case I don't understand how to do it.

Thank you!

All the best,

Atinir
atinir
 
Posts: 25
Joined: Thu Apr 21, 2016 9:20 am

Re: Storyboard IO TCP/IP Relay Application for Mobile Platfo

Postby mlove » Mon Apr 03, 2017 9:17 am

Hi,

The code that Evan linked last was for a tcp relay lua module, when compiled this would simply be a shared object (.so) that lua will load. Because you want to run the server on Android you will need to use the tcp relay lua module on that end, there’s an example of how to run the server in this way in tcp_server.zip (available above). The example is straight forward, callbacks.lua shows how to load the tcp relay library, initialize the connection, and receive an event. You will need to add this library to a user libs file when you export your APK, you can find out how to do this in our documentation (http://www.cranksoftware.com/cranksoftw ... ml#d0e5683).

On your Linux machine you could probably just use the command line tcp relay.

Regards,

Matt L
mlove
 
Posts: 18
Joined: Tue Apr 17, 2012 1:26 pm

Re: Storyboard IO TCP/IP Relay Application for Mobile Platfo

Postby atinir » Thu Apr 20, 2017 9:23 am

Hi,

Thank you Matt for the information. I tried your suggestion and it worked.

I have a question regarding bidirectional communication between the server and client, for example if I want to send an event from tcp_server to tcp_client. As I know tcp_sever can write to client only if it has received a request, but in my case I want to send an event from tcp_sever to tcp_client without client request. Is there some way how can I approach this bidirectional communication?

Thank you!

All the best,

Atinir
atinir
 
Posts: 25
Joined: Thu Apr 21, 2016 9:20 am


Return to Samples

Who is online

Users browsing this forum: No registered users and 1 guest