Hello,
Is there a way to fseek() on a socket? Or at least someway that doesn't require a linear search?
Thanks,
Yasir
Hello,
Is there a way to fseek() on a socket? Or at least someway that doesn't require a linear search?
Thanks,
Yasir
Short answer is no.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Is that a "no" to both of my questions?
Well, I'll tell you why I want to fseek() into a socket.
There is a blog, and it has become quite popular. It has over 3000 posts. The problem with this is that each time you want to access the blog, you have to download 3 MB worth of data. This is made worse by the fact the HTTP header does not send back the date last modified field, so nothing is cached. Well, I want to store each post seperately in a database, and display, say, 20 entries on a page at once. There will be links to different page number, like a regular message board. The problem here is that I don't have access to the database or whatever they are using to store the data. So I plan on having a link that says "last page" that when clicked will go to the last 20 posts. I plan on doing this by storing a file pointer up to the point the last entry into the blog. When "last page" is clicked, I will use the file pointer to look ahead if there is a new post, and if so, add the new post to the database and increment the file pointer. The file pointer itself is stored within a database.
This way I am also doing the website administrator a favor by reducing his bandwidth (even though that is not my intention).
I can post the link to the blog, but I fear that I may be moderated, because the blog itself isn't moderated and people with ill intentions have posted obscene stuff (but it is only a fraction of a fraction of fraction of the total posts).
Of course, I would appreciate a better solution than storing a file pointer.
Thanks,
Yasir
Last edited by Yasir_Malik; 05-21-2005 at 05:19 PM.
The way that HTTP typically works is that a client opens a connection and requests a document, the server sends the response and closes the connection. It is very unlikely you will be able to keep the connection permanently open waiting for new entiries. I suggest that the website administrator install one of the many free blog software packages. Or relocate most of the entries to archive pages. If the entries are posted newest first you could request the blog page and then just close the connection after any new entries.
Last edited by anonytmouse; 05-22-2005 at 04:55 AM. Reason: Spelling.
RFC2616 Hypertext Transfer Protocol -- HTTP/1.1
Get it at http://www.rfc-editor.org
I suggest you read it thoroughly before you do much more.
If your blog HTML simply grows in size (appended to only), then I suggest you look into the "range" feature of HTML requests.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
No, I didn't intend to keep the socket open with a call to select() or whatever, but I intended to keep the data byte offset (the file pointer) around, so each time "last page" would be clicked, I would reopen the connection to the site and use the file pointer to move to the last entry I read.Originally Posted by anonytmouse
This sounds promising. I'll look into this. Thanks.Originally Posted by salem
Last edited by Yasir_Malik; 05-22-2005 at 06:56 AM.
By the way, here's the blog:
http://brokensaints.com/blog/?p=48
It is probably the biggest blog you'll ever see.
When I send the following message, I get the entire the page back:
SendingCode:GET /stuff.html HTTP/1.1\r\n Host: localhost\r\n Accept: text/html\r\n Content-Range: bytes 0-2/*\r\n Connection: Close\r\n\r\n
also returns the entire page. I'm running Apache 2.0.52.Code:GET /stuff.html HTTP/1.1\r\n Host: localhost\r\n Accept: text/html\r\n Content-Range: bytes 3000000-3000002/*\r\n Connection: Close\r\n\r\n
Thanks,
Yasir
My guess would be the * is doing something.
Or you HTTP server either isn't 1.1 compatible (seems unlikely), or isn't set up to deal with ranges.
Have you spied the connection request/response with say ethereal?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
According to the RFC, you are allowed to use * if you don't know the size of the data. Nevertheless, I used 3056950, which is the size of the data, but still got the same result.Originally Posted by Salem
Yeah, I except Apache 2 to be fully HTTP 1.1 compliant.Or you HTTP server either isn't 1.1 compatible (seems unlikely), or isn't set up to deal with ranges.
I have dial up, and I don't want to spend time downloading the package (it's almost 6 MB).Have you spied the connection request/response with say ethereal?
However, this is the response I got from the server:
Since I am not using a browser, the request is what I posted in my last post because I am sending everything through a socket I created in a PHP program.Code:HTTP/1.1 200 OK Date: Sun, 22 May 2005 19:44:37 GMT Server: Apache/2.0.52 (Unix) PHP/5.0.2 Last-Modified: Sun, 22 May 2005 17:12:59 GMT ETag: "6b17-2ea536-11265cc0" Accept-Ranges: bytes Content-Length: 3056950 Connection: close Content-Type: text/html; charset=ISO-8859-1
Well 6MB is well worth it IMO - given the amount of help it's likely to be in figuring out all sorts of network coding problems.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
My development box is NetBSD and it is not networked. My Windows box is networked, but it's dialup. Just to install Ethereal, I need the packages metioned here:
ftp://ftp.netbsd.org/pub/NetBSD/NetB...al/README.html
I probably have some of them, and I might not even have the right version. I'm probably going to be in dependency hell. Downloading everything will be definetly more than 6 MB. The CS server doesn't have Ethereal or else I could ssh in and run Ethereal. The sysadmin is a lazy and is obsessed with security (he makes us run the CGI version of PHP when there's entire corporations that run regular PHP), and probably won't install it.
But what more do you need other than the response from the server (I'm communicating with localhost)?
> My development box is NetBSD and it is not networked
So how do you develop a networking program, if there's nothing to talk to?
So long as the machines are on the same local subnet, you can run ethereal on any of them, and see all local traffic no matter which machine originated it.
You don't have to run ethereal on the machine actually sending/receiving the traffic.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.