|
|
#232 (permalink) |
|
Senior Member
Join Date: Apr 2006
Posts: 1,050
|
i think they're holding out on jello for the next next iphone. it's not that they don't have the tech, they just don't wanna set the bar too high. personally i'm with you though, without jello the ball tonging seems almost pointless. |
| (Offline) |
|
|
|
#234 (permalink) |
|
Administrator
Join Date: Mar 2008
Location: Detroitish
Posts: 1,654
|
Ok this is the PHP I am using to listen for incoming data.
Code:
<?php
$pushNotifications = new pushNotifications();
class pushNotifications {
/*private $serviceHost = '127.0.0.1';*/
private $serviceHost = '192.168.0.102';
private $servicePort = '1233';
private $serviceConnection;
function __construct(){
$this->listenForClients();
$this->closeConnections();
}
function listenForClients(){
$this->serviceConnection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($this->serviceConnection, $this->serviceHost, $this->servicePort);
socket_listen($this->serviceConnection, 10);
while($clientSocket = socket_accept($this->serviceConnection)){
$clientMessage = socket_read($clientSocket, 1024);
$filename = 'tokenLog';
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $clientMessage will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $clientMessage to our opened file.
if (fwrite($handle, $clientMessage) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($clientMessage) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
socket_close($clientSocket);
}
}
function closeConnections(){
socket_close($this->serviceConnection);
}
}
?>
and it works fine. I can do: Code:
telnet 192.168.0.102 1233 once I'm connected to telnet I can type in whatever and hit enter and it gets written to tokenLog. This works reliably. So I've written some objective-c code to send some data to the server but I can't get it to bind. Here's where I'm stuck: Code:
- (void)sendProviderDeviceToken {
NSLog(@"sendProviderDeviceToken");
int fd = -1;
CFSocketRef socket;
socket = CFSocketCreate(kCFAllocatorDefault,
PF_INET,
SOCK_STREAM,
IPPROTO_TCP,
0,
NULL,
NULL);
if ( socket == NULL) {
NSLog(@"CfSocketCreate Failed");
}else{
if( socket ) {
fd = CFSocketGetNative(socket);
if (fd == -1) {
NSLog(@"CfSocketGetnative Failed");
} else {
int yes = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_port = htons(1233); //port
inet_aton("68.43.107.247", &addr.sin_addr); //ip adress
NSData *address = [NSData dataWithBytes:&addr length:sizeof(addr)];
CFSocketError e = CFSocketSetAddress(socket, (CFDataRef)address);
if(e != kCFSocketSuccess ) {
NSLog(@"Could not bind to address");
} else {
char msg []= "helloworld";
CFDataRef Data = CFDataCreate(NULL, (const UInt8*)msg, sizeof(msg));
CFSocketSendData(socket,NULL, Data, 1000);
NSLog(@"Data Sent");
}
}
} else {
NSLog(@"No server socket");
}
}
}
__________________
KATGIPHONE Donation ![]()
|
| (Offline) |
|
|
|
#235 (permalink) |
|
Administrator
Join Date: Mar 2008
Location: Detroitish
Posts: 1,654
|
Ok tackled most of my problems with this:
Code:
- (void)sendProviderDeviceToken:(id)deviceTokenBytes {
NSLog(@"sendProviderDeviceToken");
CFWriteStreamRef myWriteStream = nil;
CFReadStreamRef myReadStream = nil;
CFStringRef url = CFSTR ("whywontyoudie.com");
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault,
url,
1233,
&myReadStream,
&myWriteStream);
//CFDataRef Data = CFDataCreate(NULL, (const UInt8*)deviceTokenBytes, sizeof(deviceTokenBytes));
const UInt8 *test = (UInt8*)&deviceTokenBytes;
if (myWriteStream != Nil && CFWriteStreamOpen (myWriteStream)==true && CFReadStreamOpen (myReadStream)==true) {
CFIndex result = CFWriteStreamWrite ( myWriteStream, (UInt8*)&deviceTokenBytes, sizeof(deviceTokenBytes));
}
}
|
| (Offline) |
|
|
|
#238 (permalink) |
|
Administrator
Join Date: Mar 2008
Location: Detroitish
Posts: 1,654
|
Ok need somebody who's better at php than me.
This accepts an url with a variable like ?dev=<11111 11111 1111 11111> and writes it to a log file with <deviceToken></deviceToken> wrapped around it. Whats the best way to check for and remove duplicate entries. Code:
<?php
$deviceToken=$_GET['dev'];
$filename = 'tokenLog';
$front = '<deviceToken>';
$back = '</deviceToken>';
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $clientMessage will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $clientMessage to our opened file.
if (fwrite($handle, $front.$deviceToken.$back) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($clientMessage) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
Code:
<deviceToken><c32f8b7c e8d02a51 ce296c62 d3da4cb3 84fed78d b24545db fd949a73 132f2b50></deviceToken> |
| (Offline) |
|
|
|
#239 (permalink) |
|
Senior Member
Join Date: May 2007
Location: pacinian corpuscle.
Posts: 1,868
|
Can you keep the entries in a hash table in memory and dump to file periodically?
Checking for dupes each time you write to a file is gonna be a bottleneck. But I haven't hit this thread up in a while. Lemme reed thru the archives. |
| (Offline) |
|
|
|
#240 (permalink) |
|
Administrator
Join Date: Mar 2008
Location: Detroitish
Posts: 1,654
|
I might write a python script and set it up as a cron job. Might just do it in the push notification app. If there's an effective way to do it using something like pythons sets I would be into that.
|
| (Offline) |
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|