views:

183

answers:

0

Hi,

i'm having trouble to asatblish a CFSocket connection to a java server from iphone. Server is listening on port 80.

Wireless LAN connection works great. EDGE NOT (T-Mobile)

One Strange thing: If i first go to safari and open a website which address is my server ip and then start the app it connects.

Please help me! I'm really having no more ideas :(

iPhone connects using this function:

-(BOOL)connect{

    struct sockaddr_in ipAddress;
    ipAddress.sin_family = AF_INET;
    ipAddress.sin_port = htons(port);
    ipAddress.sin_addr.s_addr = inet_addr([srvaddr UTF8String]);

    data = CFDataCreate(NULL, (UInt8 *)&ipAddress, sizeof(struct sockaddr_in));
    CFSocketSignature sig = {PF_INET, SOCK_STREAM, IPPROTO_TCP, data};

    CFOptionFlags registeredCallbacks = kCFSocketReadCallBack|kCFSocketDataCallBack|kCFSocketConnectCallBack|kCFSocketWriteCallBack;
    CFSocketContext socketCtxt = {0, self, NULL, NULL, NULL};

    socket =  CFSocketCreateConnectedToSocketSignature(NULL, &sig, registeredCallbacks , socketCallback, &socketCtxt, 0);

    if(socket == NULL){ 
     return NO;
    }
    else{
     CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, socket, 0);
     CFRunLoopRef loop = CFRunLoopGetCurrent();
     CFRunLoopAddSource(loop, source, kCFRunLoopDefaultMode);

     return YES;
    }
}