473,387 Members | 1,785 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,387 software developers and data experts.

Download using socket

I want to download a file using socket programming (and
not httprequest) but the DNS keeps giving me errors "IP
is ok, but the attached data is not available"

I am doing like this and the address is ok. does any one
know what is wrong here?

IPHostEntry lipa =
Dns.Resolve("192.168.0.2/image.jpg");

IPEndPoint lep = new
IPEndPoint(lipa.AddressList[0], 80);
Socket s = new Socket
(lep.Address.AddressFamily,
SocketType.Stream,
ProtocolType.Tcp);
try
{
s.Connect(lep);
}
catch (Exception e)
{
Console.WriteLine
("Exception Thrown: " + e.ToString());
}

/*
byte[] msg =
Encoding.ASCII.GetBytes("This is a test");

// Blocks until send
returns.
int i = s.Send(msg, 0,
msg.Length, SocketFlags.None);
*/

// Blocks until read
returns.
byte[] bytes = new byte
[1024];
byte[] inBuf = new byte
[HttpBuffer];
s.Receive(inBuf, 0,
s.Available, SocketFlags.None);

//Displays to the screen.
//Console.WriteLine
(Encoding.ASCII.GetString(bytes));
s.Shutdown
(SocketShutdown.Both);
s.Close();
Nov 15 '05 #1
1 3660
"Henrik" <hh@attento.dk> wrote in message
news:0f****************************@phx.gbl...
I want to download a file using socket programming (and
not httprequest) but the DNS keeps giving me errors "IP
is ok, but the attached data is not available"

I am doing like this and the address is ok. does any one
know what is wrong here?

[snip]

You can't do it like this... Socket is a connection to the process not to
the file. Once you establish your connection you need to use the protocol
the server is using - http, most likely, in this case.
Nov 15 '05 #2

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

Similar topics

6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
8
by: kieran | last post by:
Hi, I want to download an image from the web and save it locally. I have spent all day messing about with this and am still no where. We have a firewall so i use the below code. I know it...
1
by: bobano | last post by:
Hi everyone, I am writing a POP3 Client program in Perl. You connect to a POP3 Server and have a running conversation with the mail server using commands from the RFC 1939 Post Office Protocol....
7
by: John | last post by:
We have created a game and when the user click on "Download New Songs" which requires the user to download songs. This could be over 20 songs. I have these files zipped on the server in one...
2
by: Jan Janssen | last post by:
Dear sir/madam, I am writing a program which is some kind of moviedatabase based on a struct filled with information from a textfile. I'm trying to build an update function which downloads a...
2
by: lokeshRsharma | last post by:
Hi, i am using Win32 sockets in Windows mobile 5.0 smartphone. My data size is around 10k. I perform following actions to download data from server : 1. Enable ConnectionManager when...
2
by: fepeacock | last post by:
I am breaking/interrupting my connection with the ftp server at present when doing a partial download of a file. I have a callback with retrbinary that raises an exception and ends the download....
3
by: konstantin | last post by:
Hi, I wonder if there is a safe way to download page with urllib2. I've constructed following method to catch all possible exceptions. def retrieve(url): user_agent = 'Mozilla/4.0...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.