iphone sdk/mac - 套接字的另一个问题
我的程序由两部分组成 - 在不同线程上运行的服务器套接字(位于端口 3490 上)和用于测试服务器的客户端。现在服务器有一个 pdf 文件,我希望客户端在 UIWebView 中显示它。为了实现这一点,我使用了以下内容:
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1:3490/"]];
[webView loadRequest:urlRequest];
问题是,当服务器发布其请求时,我会进入控制台: 无法打开'':没有这样的文件或目录
在服务器中,代码最重要的部分是:
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");
}
基本上我想做的是通过套接字将文件发送到客户端。也许这里出了什么问题。 服务器的其余部分相当长,所以我只提供它的链接(它已修改 - 我使用 sendFile 而不是发送)。 http://beej.us/guide/bgnet/output/ html/multipage/clientserver.html#simpleserver
请帮忙
谢谢
亚历克斯
编辑:没关系。我解决了这个问题。 open(viewController.filePath, O_RDONLY) 中似乎需要 [viewController.filePath UTF8String];
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系。我解决了这个问题。 open(viewController.filePath, O_RDONLY) 中似乎需要 [viewController.filePath UTF8String];
Nevermind. I solved the issue. it seems that [viewController.filePath UTF8String] is needed in open(viewController.filePath, O_RDONLY);