views:

125

answers:

1

Hi guys,

My program consists of 2 parts - A server socket (sits on port 3490) running on a different thread, and a client to test the server. Now the server has a pdf file, and I want the client to display it in a UIWebView. To achieve this I used the folllowing:

    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1:3490/"]];
[webView loadRequest:urlRequest];

The problem is that when a server posts its request I get in the console: unable to open '': No such file or directory

In the server the most important part of the code is:

int fileDesc = open(viewController.filePath, O_RDONLY);

            if (fileDesc == -1) {
                fprintf(stderr, "unable to open '%s': %s\n", viewController.filePath, strerror(errno));
                exit(1);
            }

            off_t offset = 0;
            off_t len = 0;
            struct sf_hdtr headers;
            headers.headers = NULL;
            headers.trailers = NULL;
            if (sendfile (fileDesc, new_fd, offset, &len, &headers, 0) == -1){
                perror("send");
            }

Basically what I'm trying to do is to send the file via the socket to the client. Probably something is wrong here. The rest of the server is pretty long so I'll just provide the link to it (It's modified - instead of send I use sendFile). http://beej.us/guide/bgnet/output/html/multipage/clientserver.html#simpleserver

Please help

Thanks

Alex

EDIT: Nevermind. I solved the issue. it seems that [viewController.filePath UTF8String] is needed in open(viewController.filePath, O_RDONLY);

A: 

Nevermind. I solved the issue. it seems that [viewController.filePath UTF8String] is needed in open(viewController.filePath, O_RDONLY);

Alex1987