sockets - Sth Wrong with the CFSocket on ios server side, the callback function is not be called -
sockets - Sth Wrong with the CFSocket on ios server side, the callback function is not be called -
i build online game on iphone , need code found connection between 2 players, not bonjour , must utilize socket way this. , here's code on client, works when running on mac, not work on iphone device testing. has no clue goes wrong,and bothers me alot . has same problem? log says socket listening on port,but acceptcallback function not called,what's wrong?
cfsocketref sserveripv4;
cfsocketcontext ctx4 = { 0, null, null, null, null }; sserveripv4 = cfsocketcreate(kcfallocatordefault, pf_inet, sock_stream, ipproto_tcp, kcfsocketacceptcallback, acceptcallback, &ctx4); cfsocketref sserveripv6; cfsocketcontext ctx6 = { 0, null, null, null, null }; sserveripv6 = cfsocketcreate(kcfallocatordefault, pf_inet6, sock_stream, ipproto_tcp, kcfsocketacceptcallback, acceptcallback, &ctx6); if (sserveripv4 == null) homecoming -1; if (sserveripv6 == null) { homecoming -2; } int yes = 1; setsockopt(cfsocketgetnative(sserveripv4), sol_socket, so_reuseaddr, (void *)&yes, sizeof(yes)); setsockopt(cfsocketgetnative(sserveripv6), sol_socket, so_reuseaddr, (void *)&yes, sizeof(yes)); struct sockaddr_in sin; memset(&sin, 0, sizeof(sin)); sin.sin_len = sizeof(sin); sin.sin_family = af_inet; sin.sin_port = htons(port); sin.sin_addr.s_addr = htonl(inaddr_any); cfdataref sincfd = cfdatacreate(kcfallocatordefault, (uint8*)&sin, sizeof(sin)); cfsocketsetaddress(sserveripv4, sincfd); cfrelease(sincfd); struct sockaddr_in6 sin6; memset(&sin6, 0, sizeof(sin6)); sin6.sin6_len = sizeof(sin6); sin6.sin6_family = af_inet6; sin6.sin6_port = htons(port); sin6.sin6_addr = in6addr_any; cfdataref sin6cfd = cfdatacreate(kcfallocatordefault, (uint8*)&sin6, sizeof(sin6)); cfsocketsetaddress(sserveripv6, sin6cfd); cfrelease(sin6cfd); cfrunloopsourceref socketsource = cfsocketcreaterunloopsource(kcfallocatordefault, sserveripv4, 0); cfrunloopaddsource(cfrunloopgetcurrent(), socketsource, kcfrunloopdefaultmode); cfrunloopsourceref socketsource6 = cfsocketcreaterunloopsource(kcfallocatordefault, sserveripv6, 0); cfrunloopaddsource(cfrunloopgetcurrent(), socketsource6, kcfrunloopdefaultmode); printf("socket listening on port %d\n", port);
ios sockets connection server-configuration cfsocket
Comments
Post a Comment