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.

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.

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.

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.

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 for addressing this interesting topic about communication via TCP/IP .

I tried to use example above to make simple chatting between PC platform ( as server ) and android app ( as client ) with connection successful , but my problem is I con't send or received data (text string) !

What target (Windows, Linux, Mac) are you trying to compile you binaries for the PC platform?

The reason I ask is that you have mixed and matched your compile lines in what you have posted. The include and lib lines that you are using are for an Android armle platform, but the compiler you are using is core a QNX x86 system.

Thanks for your reply ... yes I working on windows, my target is Android platform *.apk by Storyboard, as chatting between PC( as server by vb.net ) and Android platform app ( as client by storybord ) I want to know how I use TCP/IP to sand and received data,when i turn on client app on android device the server connected dirctly on clinet , but i con't send or received between them

in the expamel above ( tcp_client.zip) the name of event it's not exist on sbio_tcprelay.c ?? how event work with sbio_tcprelay.c ?- I make successful connected TCP/IP ( as img ) , but i cant transfer data , how i can make it ??

The TCP relay that we are using in this example is a cover for using Storyboard IO through a TCP connection. Your server probably doesn't know anything about Storyboard IO, so it isn't really going to be able to do anything with the connection that you are setting up from the Storyboard application.

For what you are trying to do, I would recommend something like Lua sockets. More information on Lua sockets can be found here: