English 中文(简体)
采用IPhone语的版本
原标题:Using socket API on IPhone

我必须完成以下任务:

  • open a TCP socket
  • send a command to the server
  • shutdown the WRITE part of the connection
  • read the response from the server
  • close the connection

I m没有列入袖珍方案——我刚刚开始使用网络方案,I ve已经使用<代码>CFStream接口。 但是,显然上游不足以完成这项任务。

谁能把我引向正确的方向? 我试图在阿普洛斯网站找到一张关于袖珍的地图,但没有任何东西。

问题回答

我并不是一个老板,但我对你的问题感到奇怪,因此,我对你们的问题进行了思考。

我发现这一页:。 www.un.org/Depts/DGACM/index_spanish.htm

该法典:

- (void)sendcmd:(NSString*)cmd {

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *hostname= [defaults stringForKey:@"hostname"];

    NSHost *host=[NSHost hostWithName:hostname];

    if (host) {

        struct sockaddr_in addr;
        int sockfd;

        // Create a socket
        sockfd = socket( AF_INET, SOCK_STREAM, 0 );

        addr.sin_family = AF_INET;
        addr.sin_addr.s_addr = inet_addr([[host address] UTF8String]);
        addr.sin_port = htons( 2001 );

        int conn = connect(sockfd, &addr, sizeof(addr)); 

        if (!conn) {

            NSData* data = [cmd dataUsingEncoding:NSISOLatin1StringEncoding];

            ssize_t datasend = send(sockfd, [data bytes], [data length], 0);
            datasend++;

            //ssize_t   send(int, const void *, size_t, int) __DARWIN_ALIAS_C(send);

            close(sockfd);

        } else {
            // create a popup here!

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[@"Connection failed to host " stringByAppendingString:hostname] message:@"Please check the hostname in the preferences." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
            [alert release];
        }

    } else {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[@"Could not look up host " stringByAppendingString:hostname] message:@"Please check the hostname in the preferences." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }

}

一位海报还提出这一图书馆:entropydb - SocketWrapper





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

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 ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签