I am really curious, has anyone actually got UDP networking fully functional with a recent version of Marmalade (Eg 6.0.5)? Over a period of about two weeks, I’ve really been banging my head against the wall. I’m trying to get a simple test case working where a device such as an Android Galaxy SIII, or an iPad 1.0 can receive UDP packets.
I’ve tried the following approaches:
(1) Write my own “raw” transport scheme using s3e socket functions directly:
Result:
Works fine on exe simulator. The exe simulator can send, recv, and interpret UDP packets just fine.
But as soon as I deploy the exact same code to a device, either android or ipad, it ceases to work properly. Now here is a strange thing, when the code is running on a mobile device, it seems to be able to “send” packets out without a problem. But as soon as the device is asked to receive packets, it has shown the following behaviors:
(1) Receives packets intermittently for a few seconds, and then crashes.
(2) Seemingly does “nothing” for a few seconds, and then crashes
(3) Crashes instantly as soon as packets are received.
Each of the above three behaviors was replicated on the Android and ipad, while at the same time the simulator version works without a problem.
As some of the forum posts suggested, I tried playing with the stack-size setting in the .icf file, to no avail.
(2) Try implementation with ENET:
First coded up enet directly on osx using minimum tutorial code. Bi-directional communication works fine between both “a.out” instances. However, enet on top of marmalade doesn’t seem to want to connect to my other a.out server running enet. That's about as far as I got with ENET.
(3) Try implementation with RakNet:
This approach looked really promising, because RakNet is a named marmalade partner, and has an actual “factory configured” .mkb file. I was able to get RakNet successfully integrated within the marmalade project. Since by this point, I had solidly narrowed down the concern to receiving UDP packets on devices, I focused solely on this part of the problem. I wrote a RakNet “sender” again as an a.out file. Then I had the RakNet receiving code set-up within Marmalade. I started up the exe simulator first, and then powered up the a.out “sender”. (Incidentally, the sender and receiver are on two different machines in case that wasn’t clear before) So at this point things are looking really promising. The .exe marmalade simulator is receiving, and interpreting a 30 fps packet stream coming from RakNet on my OSX box. I’m thinking that this will be a sure winner. So I deploy the code (just proven in the simulator) to my Android / iPad. Then I repeat the same process one at a time. Power up the android app, (it’s waiting for RakNet connection). Then power up the RakNet packet sender. In all cases the app on the device crashes just after making the RakNet connection. On the sender side RakNet reports the following:
T-iMac:RakNet matt$ ./a.out
(C) or (S)erver?
c
Enter server IP or hit enter for 127.0.0.1
192.168.0.195
Starting the client.
Our connection request has been accepted.
sending to 192.168.0.195
Prepping Gamestate Packet of [84] bytes
Prepping Gamestate Packet of [84] bytes
Prepping Gamestate Packet of [84] bytes
Prepping Gamestate Packet of [84] bytes
Prepping Gamestate Packet of [84] bytes
Prepping Gamestate Packet of [84] bytes
Prepping Gamestate Packet of [84] bytes
Prepping Gamestate Packet of [84] bytes
…
At this point RakNet keeps sending packets, but the RakNet on the Anrdoid device promptly crashes after receiving a few packets. Interestingly enough, RakNet reports that it made a connection with the Android device (195). I repeated the process with the iPad as a device and got the exact same results.
At this point I’m really banging my head against a wall. Why does the device always choke up when receiving packets, but it has worked fine in the simulator. I double checked my android manifest, yes all permissions are enabled. I’ve also been running the increased stack size suggested by some forum posts.
(4)
Not knowing where else to turn, I try each of the s3e networking examples:
s3eSocket
s3eThreadNetwork
s3eZeroConf
s3eSharedWhiteboard
In each case, I get the same general theme as before. Some successes in the simulator, no rock solid functional example of receiving data on a mobile device. The sharedWhiteboard example was an interesting one. I load the shared white board on the simulator, and then also onto my android device. As soon as I start drawing into the android device, the simulator running on my PC immediately crashes: “Unhandled exception at 0x61cfee13 (s3eSharedWhiteboard.s86) in s3e_simulator_debug.exe: 0xC0000005: Access violation writing location 0x01f2126. When I go the other way around, drawing into the simulator, nothing happens on the android device.
So here is the point I’m at. I’m not asking anyone to debug my code, I’m certain that it is working fine. I’m just looking for some example, any minimal example of UDP working properly, between the simulator and a device. I mean, I can’t even get the whiteboard example working on marmalade 6.0.5. Is anyone else having similar problems? Is it a bug with Marmalade?
PS:
I love just about everything else about the marmalade Architecture. Everything else has been *super* easy. I’ve already successfully ported a native iOS android app, and got it into the android store in just under two days (“Geom3d”). I’m not a complete newb, but this networking stuff on Marmalade is driving me bonkers!
PPS: I've searched that forums and discovered that others were having UDP problems around the ~2011 timeframe, but in several cases the final "fix" was never posted.
Eg: s3eSocketRecv not working with UDP
"I took the s3eSocket example and tried to modify it to run on UDP. After doing this, I was able to send UDP messages but I was never able to receive any messages..."
"Severe Problems with Android..."
"sendmsg/recvmsg odd behavior"












I have plans to port my debugging lib that uses UDP. Very interesting to follow your updates with UDP. Keep us updated if you will work around the problem.
May be simpler to create your own EDK ext for UDP ?
Thanks
Roo,
Thanks for the reply & encouragement. Since the post, I've thought of possibly trying an earlier version of Marmalade.
Worst comes to worst, I might resort to TCP, although this would break most of my comms architecture, and I'd have to re-write some code to use stream communications vs message based communications.
>>"May be simpler to create your own EDK ext for UDP ?"
As for creating my own EDK, I was really hoping to avoid anything like that. I recently paid the $499 Indy fee to avoid worrying about device issues like this.
I'm still curious, without any obligation to post code, yay or nay, who had some form of UDP working properly on mobile devices with the latest version of Marmalade? I'd like to get a sense of if this is a systemic issue, or just me.
I have an UDP listener using s3esockets running. At least in previous marmalade versions, and AFIK in 6.0.5 it works still. But to be honest it is a very simple part with only a few s3esockets functions used, it is a listener to watch for udp messages to get gps nmea data from a simulator we use for testing. Since it is only used for testing it is used only by a limited number of people, so I do not have any widespread experience.
FlyingRob, thanks for the update. I'm going to take one last stab at a minimal code example to see if I can replicate the problem, or achieve success. Either way, I'll post my results.
I think I might have a success story.
I'll post some example code tonight once I confirm everything is working.
/*
Okay, so here is the simple sanity check / test benchmark I got working.
You should be able to send some packets from the simulator to your device, and vice versa. Works great on my android and Samsung Galaxy SIII. The only remaining anomaly seems to be that my android won't get the first 'hello' packet, but it does get the next three.
*/
//-------------------------------------------------------------------
//By mk_ultra 2012
#include "s3e.h"
#include
#include
#define OUR_PORT 25000
//-------------------------------[My Poor Mans Console]--------------------------------
#define MAX_LINES 100
int curr_line=0;
int curr_y_position;
int textHeight=0;
int usable_lines;
char lines[MAX_LINES][80];
int frame=0;
//-------------------------------[My Poor Mans Console Methods]--------------------------------
void initConsole()
{
textHeight = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT);
usable_lines = (s3eSurfaceGetInt(S3E_SURFACE_DEVICE_HEIGHT) / textHeight) * 0.90 ;
curr_y_position=20;
curr_line=0;
for(int c=0;c
full code: