使用TCP套接字在后台模式(ios)中运行示例应用程序。当客户端发送任何消息并等待另一条消息时,它会给出消息(本地通知)。当应用程序在调试中运行时,它会正常工作,但在发布时会崩溃10秒后模式。 使用:xcode 4.2& iPad 2用于测试..
这是我正在使用的代码:
struct sockaddr_in serv_addr, cli_addr;
CFReadStreamRef hReadStream;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) printf("Sockfd Error\n");
bzero((char *) &serv_addr, sizeof(serv_addr));
portNo = 3600;//atoi(argv);
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portNo);
if (bind(sockfd, (struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0)
printf("bind error\n");
listen(sockfd,5);
clilen = sizeof(cli_addr);
newsockfd = 1;
while(newsockfd)
{
newsockfd = accept(sockfd,
(struct sockaddr *) &cli_addr,
&clilen);
NSLog(@"newsockfd create %d\n",newsockfd);
remoteAdd = inet_ntoa(cli_addr.sin_addr);
//cout << remoteAdd << " port = " << cli_addr.sin_port << endl;
portNo = cli_addr.sin_port;
#if defined(__IPHONE_4_0) && !(TARGET_IPHONE_SIMULATOR)
NSLog(@"newsocket %d\n",newsockfd);
// Only do this if it is a SipSocket we are watching
if (newsockfd)
{
// Set it to non-blocking
//int set = 0;
//ioctl(newsockfd, FIONBIO, reinterpret_cast<int>(&set));
CFStreamCreatePairWithSocket (kCFAllocatorDefault, newsockfd,
&hReadStream, NULL);
if (CFReadStreamSetProperty(hReadStream,
kCFStreamNetworkServiceType,
kCFStreamNetworkServiceTypeVoIP) != TRUE)
{
// An error occured, delete the stream
if(hReadStream != NULL)
{
CFReadStreamClose(hReadStream);
CFRelease(hReadStream);
hReadStream = NULL;
}
//return -1;
}
else NSLog(@" >>>>>>>>>>>>>>>>>>> property set Here <<<<<<<<<<<<<<<<\n");
if (CFReadStreamOpen(hReadStream) != TRUE)
{
// An error occured, delete the stream
if(hReadStream != NULL)
{
CFReadStreamClose(hReadStream);
CFRelease(hReadStream);
hReadStream = NULL;
}
// return -1;
}
else NSLog(@"read....\n");
}
#endif
[self test];
}
设备日志中的崩溃报告:
"Application 'Demo' exited abnormally with signal 9: Killed: 9" &
"unknown ReportCrash[10915] <Error>: Saved crashreport to
/var/mobile/Library/Logs/CrashReporter/servertest_2011-12-13-163920_EyeBalls-iPad.plist
using uid: 0 gid: 0, synthetic_euid: 501 egid: 0"
试图找到错误,但它在调试模式下工作正常在设备日志或调试窗口中找不到任何错误。请帮助我:(
答案 0 :(得分:0)
您可以将编译器选项切换到llvm gcc4.2。我猜这个问题与铿锵有关。 希望它能正常工作。