Alright, I have a rather odd question here. I feel much more comfortable writing code in Objective-C over any other language. I recently had to do some server-side programming, which required me to learn PHP. It works, yeah, but for fun I want to achieve the same thing through Objective-C. So, I created a binary using Xcode's Foundation preset. Here's most of the binary:
#import <Foundation/Foundation.h>
#import "JSONKit.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *theURL = [NSString stringWithFormat:@"http://blahblahblah.com/blah"];
NSError *err = nil;
NSURLResponse* response = nil;
NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] init] autorelease];
NSURL*URL = [NSURL URLWithString:theURL];
[request setURL:URL];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setTimeoutInterval:30];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSDictionary *someData = [data objectFromJSONData];
NSString *someString = [[someData objectForKey:@"foo"]objectForKey:@"bar"];
//do something
[pool drain];
return 0;
}
Quite basic code. It simply downloads some stuff from my server and I parse the JSON result and get a string that I want to use. So, my question is - how can I run this on my Linux-based server? I know it's possible, maybe using GNUStep (or cocotron?), which I don't know how to use. Anyone have ideas?
Well, I suggest the same thing as the @lacqui.. Use CGI to run your program.. and here's the steps ..
(Side note: using
CGI
is deprecated as it starts a process each time a request is coming to the server (modern servers/web containers initiate a newthread
(vsprocess
).)So, let's Start:
First, let me ask you, What's the target platform to
deploy
your application?If target deployment platform is a Mac then you will have to get the binary out of xcode ( I think it would be in a .dmg format) and find some where how to run a
.dmg
as a CGI program inside a web server ( I am not sure if apache runs under Mac or not)But If it is
Windows
orLinux
:JSONKit.h
is high. If your program compiles successfully, then you are almost done.HTTP
server that haveCGI
enabled. You can follow my blogpost here to know how to deploy a binary program written in C into some small http server calledmini-httpd
on Linux (it should apply to any binary program regardless of its source language).