473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

network program

hello everyone,

i have a problem regarding networking apis of unix link systems ....i
don know this is the best place this
request but i cudnt get one .(so also suggest where to ask such
questions)

the problem is that after finally connecting to the server when i send
a get request the server returns bad request error ...i use something
like:

write(sockfd,"GET /index.html \r\n Host: 10.10.19.222:80\r\n\r\n",
50); /*the size argument actually is given */
/
*by the sizeof operator of c (here i wrote 50*/

where is the problem in the system (server ,code ,write() ,etc)
the server is apache running on my local machine ....

how are \r\n interpreted by write() .....
i use fedora8(linux)

thanks a lot
Mohan
Nov 8 '08 #1
8 1714
mohi said:
hello everyone,

i have a problem regarding networking apis of unix link systems ....i
don know this is the best place this
request but i cudnt get one .(so also suggest where to ask such
questions)
comp.unix.programmer is probably your next port of call.
the problem is that after finally connecting to the server when i send
a get request the server returns bad request error ...i use something
like:

write(sockfd,"GET /index.html \r\n Host: 10.10.19.222:80\r\n\r\n",
50); /*the size argument actually is given */
You might want to make that 44 (no null terminator) or 45 (to include the
terminator). You're trying to write more data than you have legal access
to.

For the protocol stuff, I really do recommend that you talk to
comp.unix.programmer in the first instance.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 8 '08 #2
>i have a problem regarding networking apis of unix link systems ....i
>don know this is the best place this
request but i cudnt get one .(so also suggest where to ask such
questions)
comp.unix.programmer would be a better place to ask.
>the problem is that after finally connecting to the server when i send
a get request the server returns bad request error ...i use something
like:

write(sockfd,"GET /index.html \r\n Host: 10.10.19.222:80\r\n\r\n",
50); /*the size argument actually is given */
The interpretation of \r and \n in the string literal above is
not done by write(), it's done by C for the string literal.

Manually telnet to your server on port 80 and type in the request.
I get a response before I can even start typing the " Host:" header.
I think you need to make a HTTP 1.1 request, not a HTTP 1.0 request.
See RFC2616.

My Apache will accept, and ignore, a " Host:" header, as distinguished
from a "Host:" header. However, a "Host:" header is mandatory on
a HTTP/1.1 request. Unless you include a "Host:" header, with or
without a " Host:" header, the request will fail. A " Host:" header
is just a waste of bandwidth.
Nov 8 '08 #3
In article <Uv******************************@posted.interneta merica>,
Gordon Burditt <go***********@burditt.orgwrote:
>>write(sockfd,"GET /index.html \r\n Host: 10.10.19.222:80\r\n\r\n",
50); /*the size argument actually is given */

The interpretation of \r and \n in the string literal above is
not done by write(), it's done by C for the string literal.

Manually telnet to your server on port 80 and type in the request.
I get a response before I can even start typing the " Host:" header.
I think you need to make a HTTP 1.1 request, not a HTTP 1.0 request.
See RFC2616.
A GET without a version number is a "Simple-Request" which is for
compatibility with HTTP 0.9. See RFC 1945.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Nov 8 '08 #4
On Nov 9, 3:39 am, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
In article <UvmdnQsFtbePmovUnZ2dnUVZ_jidn...@posted.interneta merica>,

Gordon Burditt <gordonb.of...@burditt.orgwrote:
>write(sockfd,"GET /index.html \r\n Host: 10.10.19.222:80\r\n\r\n",
50); /*the size argument actually is given */
The interpretation of \r and \n in the string literal above is
not done by write(), it's done by C for the string literal.
Manually telnet to your server on port 80 and type in the request.
I get a response before I can even start typing the " Host:" header.
I think you need to make a HTTP 1.1 request, not a HTTP 1.0 request.
See RFC2616.

A GET without a version number is a "Simple-Request" which is for
compatibility with HTTP 0.9. See RFC 1945.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
ok i was having an extra space before the header Host:.....but now
theres another problem

i just tried to GET the image -i show u inputs that are taken by my
program

enter the server ip address : 10.10.19.222

enter the port at which to connect to the server : 9029
sucessfully connected to the server
enter the url to request(without spaces) :http://10.10.19.222:9029/
home/Mohan/mine/web/images/tech.jpg

reading frm the server......
now after this the output from the server is saved in a file which has
contents like

HTTP/1.1 200 OK^M
Date: Sun, 09 Nov 2008 06:36:32 GMT^M
Server: Apache/2.2.6 (Fedora)^M
Last-Modified: Fri, 07 Nov 2008 12:27:31 GMT^M
ETag: "1780314-1533e9-897f32c0"^M
Accept-Ranges: bytes^M
Content-Length: 1389545^M
Connection: close^M
Content-Type: image/jpeg^M
X-Pad: avoid browser bug^M
^M
ÿØÿá<90>
ExifRL failed: 6
2009-09-26 22:31:06, Fetching URL failed: 6
h1>Moved Permanently</h1>
<p>The document has moved <a href="http://10.10.19.222:9029/home/
Mohan/">here</a>.</p>
<hr>
<address>Apache/2.2.6 (Fedora) Server at 10.10.19.222 Port 9029</
address>
</body></html>
~

but when i try to view this from the browser with exactly the same url
i have the image .....what can be wrong....

thanks a lot
Nov 9 '08 #5
On 9 Nov 2008 at 6:48, mohi wrote:
2009-09-26 22:31:06, Fetching URL failed: 6
h1>Moved Permanently</h1>
<p>The document has moved <a href="http://10.10.19.222:9029/home/
Mohan/">here</a>.</p>

but when i try to view this from the browser with exactly the same url
i have the image .....what can be wrong....
The server will have sent back a 301 status code to indicate that the
document has been permanently moved, and its new location will be
supplied in the Location header. Your browser is set up to automatically
follow this redirect, but you aren't doing so.

Nov 9 '08 #6
mohi wrote, On 09/11/08 06:48:
On Nov 9, 3:39 am, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
>In article <UvmdnQsFtbePmovUnZ2dnUVZ_jidn...@posted.interneta merica>,

Gordon Burditt <gordonb.of...@burditt.orgwrote:
<snip>>
>>I think you need to make a HTTP 1.1 request, not a HTTP 1.0 request.
See RFC2616.
A GET without a version number is a "Simple-Request" which is for
compatibility with HTTP 0.9. See RFC 1945.

ok i was having an extra space before the header Host:.....but now
theres another problem

i just tried to GET the image -i show u inputs that are taken by my
program
<snip>

This is not the right pace to discuss the HTTP protocol. HTTP does not
even have the letter C in it! There are plenty of other groups, mailing
lists and forums, please find one where HTTP is topical if you want to
discus it.
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Nov 9 '08 #7
On Nov 9, 4:25 pm, Flash Gordon <s...@spam.causeway.comwrote:
mohi wrote, On 09/11/08 06:48:
On Nov 9, 3:39 am, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
In article <UvmdnQsFtbePmovUnZ2dnUVZ_jidn...@posted.interneta merica>,
Gordon Burditt <gordonb.of...@burditt.orgwrote:

<snip>>
>I think you need to make a HTTP 1.1 request, not a HTTP 1.0 request.
See RFC2616.
A GET without a version number is a "Simple-Request" which is for
compatibility with HTTP 0.9. See RFC 1945.
ok i was having an extra space before the header Host:.....but now
theres another problem
i just tried to GET the image -i show u inputs that are taken by my
program

<snip>

This is not the right pace to discuss the HTTP protocol. HTTP does not
even have the letter C in it! There are plenty of other groups, mailing
lists and forums, please find one where HTTP is topical if you want to
discus it.
--
Flash Gordon
If spamming me sent it to s...@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me athttp://clc-wiki.net/
sorry guys for this ...
but iam not getting a place to discuss allthis
can anyone suggest any lik where i can discuss http protocol

thanks a lot
Nov 9 '08 #8
>i just tried to GET the image -i show u inputs that are taken by my
>program
u died after taking a job at the United Nations, so his advice won't
be much help..
reading frm the server......
You don't show the code that reads from the server or the code that
logs to the log file.
>now after this the output from the server is saved in a file which has
contents like
This looks like a mismash of several requests. A "moved permanently"
response should not be returning code 200. Does the message "ExifRL
failed: 6" appear in YOUR program or a library your program uses?

THIS PART REALLY IS RELEVANT TO COMP.LANG.C:
If you fread() (or use the POSIX function read()) data from the
server, then write it to a file with something like

fprintf(logfile, "%s", buffer);
you have a problem. fread() and read() do not guarantee that the
data read is terminated by a '\0' terminator, so you may end up
with extra crap written also - and it looks like you did. Use
fwrite, using the length of the data actually read, or place a
terminator before attempting to fprintf() it.

Also, you can't count on the entire response being fetched in one
fread() or read(), especially since the content sent seems to be a
bit shy of 1.4 megabytes.

>HTTP/1.1 200 OK^M
Date: Sun, 09 Nov 2008 06:36:32 GMT^M
Server: Apache/2.2.6 (Fedora)^M
Last-Modified: Fri, 07 Nov 2008 12:27:31 GMT^M
ETag: "1780314-1533e9-897f32c0"^M
Accept-Ranges: bytes^M
Content-Length: 1389545^M
Connection: close^M
Content-Type: image/jpeg^M
X-Pad: avoid browser bug^M
^M
ÿØÿá<90>
The above bytes look like the first few bytes of an actual jpeg image.
The headers suggest that the content was a little under 1.4 megabytes
long.
>ExifRL failed: 6
2009-09-26 22:31:06, Fetching URL failed: 6
h1>Moved Permanently</h1>
<p>The document has moved <a href="http://10.10.19.222:9029/home/
Mohan/">here</a>.</p>
<hr>
<address>Apache/2.2.6 (Fedora) Server at 10.10.19.222 Port 9029</
address>
</body></html>
Nov 9 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Alex Ang | last post by:
I have written the following VBScript program. It is stored into a file "map_drive.vbs". It successfully mapped to a network drive \\server1\data. Dim WshNetwork Set WshNetwork =...
12
by: Joseph | last post by:
Hello We have a web application written in ASP.Net that calls an external C# program (.exe). This C# program needs to access data from a different server and is not able to do so. We use impersonate...
0
by: Oliver | last post by:
Hello, I may have posted in the wrong place, if so, feel free to move my post (just notify me where you put it via email or something) I’m having a problem with my program that I cant...
6
by: John Walton | last post by:
Hello, everyone. I just began school, and they already assigned us science fair. Since I'm in 8th grade, I get to do demonstrations for our projects. I'm probably going to demonstrate Python's...
1
by: brian.oneil2 | last post by:
Is there a way to install this onto a network file share and allow a team to access it? I would say share a CD from a networked CD drive, but there are multiple CD's that would have to be inserted....
4
by: cmrchs | last post by:
Hi, executing the following on a local drive works fine : FileStream wLog; wLog=File.OpenRead(@"d:\Log.txt"); but executing the same code on a network drive creates a...
2
by: Marco Castro | last post by:
I have an application that reads from an access database on our network. I'm having a problem where the program can't find the database until the user tries to use the network. For example he will...
3
by: Agnes | last post by:
My client hold its MS SQL server in hkbranch, Both china and hong kong office can run the vb.net application very well via VPN. Now, they want to reduce cost and move the MS SQL server to china 's...
2
by: Mike | last post by:
Can a vb program running as a serice not use network paths to do file/io? I can't seem to get my program to work with network paths and files. When I use local disk it works fine. When I run it...
3
by: Barry Flynn | last post by:
Hi I am working with a VB 2005 program which has been converted from VB6. It writes data out to a flat file, with code like the following line WriteLine(riFileNo, "Hist", lsAssetID,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.