General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 13th, 2003, 01:04 AM
Jonx Jonx is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Southern California
Posts: 3 Jonx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Jonx
Winsock Question... Pretty Simple

I have a quick question. I am fairly new using the winsock API and I was curious how I would go about downloading a file off some specific server. Lets say I was given the exact URL of the file. How would I go about downloading that file?

I already specified the port, and the server that it is located using:

::... Assume Winsock has already been initialized...::

// Store information about the server
LPHOSTENT hostEntry;
hostEntry = gethostbyname("www.microsoft.com");


// Create the socket
SOCKET theSocket;
theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);


SOCKADDR_IN serverInfo; // Create new Socket Object
serverInfo.sin_family = AF_INET; // Specify TCP protocol
serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
serverInfo.sin_port = htons(80); // Specify Port

// Connect to the server
nret = connect( theSocket,
(LPSOCKADDR)&serverInfo,
sizeof(struct sockaddr));

::.. okay, I am now connected to microsoft using port 80..::
As a test, lets say I wanted to download their startup page...

"index.html"

How would I go about doing that?

Thanks for the help
-Jon

Reply With Quote
  #2  
Old July 13th, 2003, 10:03 AM
iahmed iahmed is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: USA
Posts: 171 iahmed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 58 sec
Reputation Power: 6
Not sure from your posting, why you are creating a socket at port 80 for file transfering.

You can create/connect a socket with standard port FTP (port 21), and issue GET/PUT for file transfering!

Reply With Quote
  #3  
Old July 13th, 2003, 02:23 PM
Jonx Jonx is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Southern California
Posts: 3 Jonx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Jonx
I wanted to use port 80 to emulate an http client. I am able to start downloading the default file ( "index.html ? index.htm ") using this:

::.. Recieving Module ..::

ofstream outfile;
outfile.open("c:\\temp.html");

char aa[1000];

strcpy(aa,"GET / \r\n");
strcat(aa,"HTTP 1.0 \r\n\r\n");
send(theSocket,aa,sizeof(aa),0);

int temp = 1;

while( temp != 0){
nret = recv(theSocket, aa, 1000, 0);
WriteToFile(aa); // Copies the aa string into the file
}

outfile.close();

::.. ..

but for some reason, it will keep recieving the bit stream and
never stop. The file will continuously growing till 400+ megs, and If I check the contents of the file, the html code has been copied many times. Is that because of my while loop condition?

Thanks

-Jon

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Winsock Question... Pretty Simple


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT