English 中文(简体)
在科恰建立服务器/应用中心
原标题:Building a Server/Client application in Cocoa

我制定了一个比较简单的方案,对文件夹进行监视,在文件添加时加以操纵,并简单地看待正在做的事情。 弹夹通过国家行动分级,通过国家排雷中心将信息输入到我的进展观察处。

Now I need to break things up and run the watched folder/processing part on my server, and build a client to monitor the progress from multiple workstations. My problem is I don t know how to accomplish this and my searches aren t really helping me.

看来,我拿到许多过时的解决办法(WebObjects、便携式批发物体)或不完整的信息。 似乎像我这样想利用国家安全局数据回馈,但我发现的国家安全局的所有情况都像它为客户而设置的,因为它寻求一个IP地址。 建立服务器和客户与服务器连接的最佳途径是什么?

最佳回答

I would suggest using TCP for something like this. Since (I assume) you are writing this software for BSD (Mac OS X and iPhone are both BSD) you can use BSD C sockets, or an Objective-C wrapper for this. One good library for a client is CocoaAsyncSocket. I personally have written a lightweight Objective-C socket class for TCP networking called SocketKit. Usage of this library is something as follows:

// open a connection
SKTCPSocket * socket = [[SKTCPSocket alloc] initWithRemoteHost:@"SERVER_IP" port:SERVER_PORT];
// write data
[socket writeData:someData];
// read data
NSData * someData = [socket readData:4];
// close the socket
[socket close];
[socket release];

从服务器的角度来看,你可以听从使用<代码>的港口。 SKTCPSocketServer 班级:

SKTCPSocket * aSocket = nil;
SKTCPSocketServer * server = [[SKTCPSocketServer alloc] initListeningOnPort:1337];
@try {
    [server listen];
    while ((aSocket = (SKTCPSocket *)[server acceptConnection]) != nil) {
        // do something with aSocket
        [aSocket close];
    }
} @catch (NSException * e) {
    NSLog(@"Exception : %@", e);
}
[server stopServer];
[server release];

当然,使用TCP袖珍片意味着撰写自己的网络议定书。 一个简单的例子就是分四长的外地,然后是NSDictionary或这种性质的一部分。 这将使你能够完成类似于基本分配物体系统的工作。

问题回答

为什么不去看Bonjour 零配置网络(即,你不必找到服务器的IP地址)?

由于Bonjour还在Windows和OS(iPhone/iPad)上得到支持,你甚至能够使您的多功能(例如,Windows和Mac的服务器或反之亦然)或甚至拥有一台自动计算机作为你的服务器的客户(登机知道这在你的情况下是否有意义,但我只是建议)。

不幸的是,这是可可相当薄弱的地方。 网络目标(Apple) 也许应该忘记分配的物体。 实际而言,在Mac岛上没有内在的客户/服务器解决方案。 海运公司有一些体面的同龄人对生产者的 st,但它对客户/服务商来说仍然毫无用处。

我的建议是使用一个简单的教育、科学和技术预报工具。 http://code.google.com/p/coa httpserver/“rel=“nofollow”>cocoa httpserver。 • 建立客户:ASIHTTPRequest。 保持简单。 我与议定书的JSON一样:YAJL为我做了很好的工作,但就某种情况而言,有许多选择。





相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签