Note that there are some explanatory texts on larger screens.

plurals
  1. POlocal vs remote socket connections on iphone
    text
    copied!<p>I want to send OSC messages from iphone to another programme (max/msp) by creating and connecting to a udp socket. this works from the iphone simulator, i.e. when both apps are running on the same computer but not when i install the app on the phone itself.</p> <p>I think the problem could be with specifying the IP of the remote computer. I am using the sockaddr_in struct to specify IP and port info. when i run the code in the simulator it is fine to specify the IP as INADDR_ANY: </p> <p>sin_addr.s_addr = INADDR_ANY;</p> <p>when i run it on the device i'm trying to convert my IP into a hexidecimal number and specifying that instead of INADDR_ANY. This doesn't work for either the simulator or the device. </p> <p>The console shows that the the socket is connecting and sending data fine but the remote programme (max/msp) doesn't receive any data at all.</p> <p>I have tried importing the right frameworks so that it should work on both device and simulator.</p> <p>the full code follows:</p> <h1>import "UDPSocketCreate.h"</h1> <pre><code>@implementation UDPSocketCreate -(id)init { in_addr_t myAddress = 0xC0A80145; if(self =[super init]) { </code></pre> <p>//addr is an instance variable of type struct sockaddr_in </p> <pre><code> memset(&amp;addr, 0, sizeof(addr)); addr.sin_len = sizeof(addr); addr.sin_family = PF_INET; addr.sin_port = htons(3333); addr.sin_addr.s_addr = myAddress;INADDR_ANY connectAddr = CFDataCreate(NULL, (unsigned char *)&amp;addr, sizeof(addr)); OSC_initBuffer(&amp;myOSCBuff, sizeof(packetBuffer), packetBuffer); NSString *address = @"/test"; const char *utf8Address = [address UTF8String]; int addressResult = OSC_writeAddress(&amp;myOSCBuff, (char*)utf8Address); } return self; } CFSocketRef udpSocket; </code></pre> <p>// this method is called from app delegate after init </p> <pre><code>-(void)createUDPSocketRef { udpSocket = CFSocketCreate(NULL, PF_INET, SOCK_DGRAM, IPPROTO_UDP, kCFSocketWriteCallBack, myCallBack, NULL); if(udpSocket == NULL) { NSLog(@"socket create failed"); return; } CFRunLoopSourceRef runLoopSrceRef = CFSocketCreateRunLoopSource(NULL, udpSocket, 1); CFRunLoopRef rl = CFRunLoopGetCurrent(); CFRunLoopAddSource(rl, runLoopSrceRef, kCFRunLoopCommonModes); } // pressing a button on the UI triggers this method -(void)bang { int myInt = 1; int writeRestult = OSC_writeIntArg(&amp;myOSCBuff, myInt); int buffDoneResult; if (buffDoneResult = OSC_isBufferDone(&amp;myOSCBuff)) { NSLog(@"valid message in buff"); char *pack = OSC_getPacket(&amp;myOSCBuff); int packSize = OSC_packetSize(&amp;myOSCBuff); CFDataRef OSCPacketWithAddressTest = CFDataCreate(NULL, pack, packSize); CFSocketError sendError = CFSocketSendData(udpSocket, connectAddr, OSCPacketWithAddressTest, 30); NSLog(@"send error: %d", sendError); } OSC_resetBuffer(&amp;myOSCBuff); NSString *address = @"/test"; const char *utf8Address = [address UTF8String]; int addressResult = OSC_writeAddress(&amp;myOSCBuff, (char*)utf8Address); } @end </code></pre> <p>any help would be greatly appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload