Downloading file from user

Technical discussion about the NMDC and <a href="http://dcpp.net/ADC.html">ADC</A> protocol. The NMDC protocol is documented in the <a href="http://dcpp.net/wiki/">Wiki</a>, so feel free to refer to it.

Moderator: Moderators

Locked
r4v3
Posts: 22
Joined: 2003-01-14 16:24
Location: Poland

Downloading file from user

Post by r4v3 » 2003-01-27 10:15

Hi its me (again) i have few questions
1)How to use $Direction especialy number at end of this command
2)How to "decode' downloaded MyList file
3)Does <filename&path> in $Get and $SR are the same ?
It always shows File not awaliable
Thats all for now
Bye
Sorry for my ENG , but i hope u'll understand me.GreetZ

Sedulus
Forum Moderator
Posts: 687
Joined: 2003-01-04 09:32
Contact:

Re: Downloading file from user

Post by Sedulus » 2003-01-27 12:32

r4v3 wrote:1)How to use $Direction especialy number at end of this command
the number is a random number.
when both clients want to download from eachother, the one with the highest number wins. iirc
http://dc.selwerd.nl/hublist.xml.bz2
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)

qqzm
Posts: 47
Joined: 2003-01-23 07:08

Re: Downloading file from user

Post by qqzm » 2003-01-28 04:11

r4v3 wrote:Hi its me (again) i have few questions
1)How to use $Direction especialy number at end of this command
2)How to "decode' downloaded MyList file
3)Does <filename&path> in $Get and $SR are the same ?
It always shows File not awaliable
Thats all for now
Bye
1) Exactly as pointed out above.
2) The original Neo-Modus uses Huffman encoding. DC++ uses BZIP2 compression.
3) They are identical. They are case sensitive though. Other than this check for things like trailing backslashes etc...

r4v3
Posts: 22
Joined: 2003-01-14 16:24
Location: Poland

Post by r4v3 » 2003-01-28 06:56

Heh its not wiorking ,when i send:
$Search ....AAA
Server respond with $SR <ownname> <filenamewithpath><filesizeinbytes> <current openslots>/<allopenslots><hubname>
so i take <filenamewithpath> and send $Get <filenamewithpath> (after Key , lock etc...) and client respond with File not Avaliable
Its strange beacouse ther isn't drive letter in some responds.And how client knows withch file upload ?
For example
I have 2 files:
C:\Dir\file.txt
D:\Dir\file.txt
And clients sends to me : $Get Dir\file.txt , witch file shoul i upload ?.
DC protocal is strange... :)
Sorry for my ENG , but i hope u'll understand me.GreetZ

ender
Posts: 224
Joined: 2003-01-03 17:47

Post by ender » 2003-01-28 09:26

If you're sharing the complete drive, you should include the drive letter in the name - so if you share C:\Dir\file.txt and D:\Dir\file.txt, and the user requests Dir\file.txt, you should answer with 'File not shared'...
OTOH, if you just shared the 'Dir' folder from both drives, you'll have to add a suffix to one of them (DC++ adds a to the second, b to the third etc.; NMDC doesn't allow you to share two folders with identical names).

sarf
Posts: 382
Joined: 2003-01-24 05:43
Location: Sweden
Contact:

Post by sarf » 2003-01-28 09:34

r4v3 wrote:[snip]
Its strange because there isn't drive letter in some responds. And how [does the] client knows which file [to] upload?
For example
I have 2 files:
C:\Dir\file.txt
D:\Dir\file.txt
And clients send to me : $Get Dir\file.txt , which file should i upload ?.
DC protocol is strange... :)
The drive letter is not used by DC++.

DC++ would share those two directories as
Dir\file.txt (-> C:\Dir\file.txt)
Dira\file.txt (-> D:\Dir\file.txt)

In this way the problem you describe does not appear.

Sarf
---
I like people, but I like myself better.

r4v3
Posts: 22
Joined: 2003-01-14 16:24
Location: Poland

Post by r4v3 » 2003-01-28 12:25

Ok i understand.Now evrything is working
Sorry for my ENG , but i hope u'll understand me.GreetZ

ivulfusbar
Posts: 506
Joined: 2003-01-03 07:33

Post by ivulfusbar » 2003-01-28 14:04

remember that the filename in the dc-list doesn't have to anything with the name/path where it is actually stored. All you need is a map between "called on dc" to "path/name"
Everyone is supposed to download from the hubs, - I don´t know why, but I never do anymore.

r4v3
Posts: 22
Joined: 2003-01-14 16:24
Location: Poland

Post by r4v3 » 2003-01-28 15:26

thanx , now i can download files but i have problem with saving it to disk.
Jm writtening my client with Java and i have no problems with *.txt files - evrything is ok , but when I download *.jpg , *.mp3 and other binary files i cant open them.
This is how I do this:
Connection to user:
try{
ss = new ServerSocket(port);
s = ss.accept();
}catch(UnknownHostException uhe)
{
return;
}catch(IOException ioe)
{
return;
}
try{
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
os = s.getOutputStream();

}catch(IOException ioe)
{
return;
}

Afther $Send command :
int znak= br.read();
fos.write(znak);

where fos is FileoutputStream; ex. new FileOutputStream("File.dat" , true);

I thing there is a problem with outputstream maybe i shoud use some other stream ? (like DataOutputStream)

Afther download :
fos.close();

Thats all , if samoe could help me (once again)
Thanx
Sorry for my ENG , but i hope u'll understand me.GreetZ

sarf
Posts: 382
Joined: 2003-01-24 05:43
Location: Sweden
Contact:

Post by sarf » 2003-01-28 16:37

r4v3 wrote:thanx , now i can download files but i have problem with saving it to disk.
Just one thing, enclose your code within code brackets to preserve your formatting.

You should not use the BufferedReader. It is inappropriate, and might cause errors.

I read somewhere about a fixed limit after which the clients have to acknowledge each other - but I am probably wrong.

Here's my code that might fix your problem (as well as a few others along the way - as usual I do not know when to stop :) ):

Code: Select all

protected static int sReadBufferSize = 16384;

public synchronized static int getReadBufferSize()
{
	return sReadBufferSize;
}

public synchronized static void setReadBufferSize(int bufferSize)
{
	sReadBufferSize = bufferSize;
}

public static void handleStreams(InputStream is, OutputStream os)
	throws IOException
{
// use assertions here instead
	if(is == null) throw new NullPointerException("inputstream may not be null");
	if(os == null) throw new NullPointerException("outputstream may not be null");
// the only reason not to do a os.write(is.read()) is that it is *very* slow to do that many calls
	byte[] buffer = new byte[getReadBufferSize()];
	int bytesRead = 0;
	try
	{
		while(true)
		{
			bytesRead = is.read(buffer);
			os.write(buffer, 0, bytesRead);
		}
	}
	catch(IOException ex)
	{
		flush(os);
		throw ex;
	}
}

void flush(OutputStream os)
{
	try
	{
		os.flush();
	}
	catch(IOException ex) {	}
}

void close(OutputStream os)
{
	try
	{
		os.close();
	}
	catch(IOException ex) { }
}

void receiveDataToFile(InputStream is, FileOutputStream fos)
{
	BufferedInputStream bis = new BufferedInputStream(is);
	BufferedOutputStream bos = new BufferedOutputStream(fos);

	try
	{
		handleStreams(is, os);
	}
	catch(IOException ex)
	{
	}
	flush(bos);
}


void handleConnection(Socket s)
	throws ConnectionException
{
	/* After $Send command : */
// fos is a FileOutputStream
	receiveDataToFile(s.getInputStream(), fos);
	close(fos);
}


protected boolean mShouldBlock;

protected synchronized boolean getShouldBlock()
{
	return mShouldBlock;
}

protected synchronized void setShouldBlock(boolean shouldBlock)
{
	mShouldBlock = shouldBlock;
}

void setUpConnection()
	throws ConnectionException
{
	try 
	{
        ss = new ServerSocket(port);
// this here code makes sure we won't wait forever for a connection
        ss.setSoTimeout(1000);
        do
		{
	        try
	        {
	        	s = ss.accept();
// put handleconnection in a thread to handle multiple clients
	        	handleConnection(s);
			}
		    catch(SocketTimeoutException ex)
		    {
		    }
        } while(getShouldBlock())
        
    }
    catch(BindException ex)
    {
    	throw new ConnectionException("could not bind to port " + port + " - it was already taken");
    }
    catch(UnknownHostException ex)
    {
    	throw new ConnectionException("could not get IP of host");
    }
    catch(IOException ex)
    {
    	throw new ConnectionException("unspecified error", ex);
    }
}
Hope you understand it.

Sarf
---
A liberal is a conservative who has been arrested.

r4v3
Posts: 22
Joined: 2003-01-14 16:24
Location: Poland

Post by r4v3 » 2003-01-30 04:36

Now evrything is working it was problem with BufferedInputStream I changed to InputStream and now is working.Thx for help.
Sorry for my ENG , but i hope u'll understand me.GreetZ

r4v3
Posts: 22
Joined: 2003-01-14 16:24
Location: Poland

Post by r4v3 » 2003-01-30 10:50

One more question (i coudnt find answer in few protocol documentations)
How to resume disconnected downloads ?
$Get <filename>$number

what number is this i hered that is a number of resumes.
Maybe it is a number of byte I want to start download ?
Sorry for my ENG , but i hope u'll understand me.GreetZ

ender
Posts: 224
Joined: 2003-01-03 17:47

Post by ender » 2003-01-30 11:15

IIRC, it's a random number when both clients want to download, the bigger number wins... Check the docs here...

Sedulus
Forum Moderator
Posts: 687
Joined: 2003-01-04 09:32
Contact:

Post by Sedulus » 2003-01-30 11:49

r4v3 wrote:$Get <filename>$number
yes, number is the byte offset (starting at 1, not 0)
http://dc.selwerd.nl/hublist.xml.bz2
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)

Locked