mIRC Homepage

Receiving DCC files through sockets

Posted By: Rooster74

Receiving DCC files through sockets - 27/07/03 07:39 AM

I figured out how to accept dcc sends through sockets and how to send files, but I am having problems recieving them. The connection accepts, but I am missing something in the sockread portion because the file stalls mid way through every time.
Code:
on *:SOCKREAD:dcc.*:{
  if ($sockerr) { return }
  sockread 4096 &dcc
  while ($sockbr) {
    bwrite %filename -1 -1 &dcc
    sockread 4096 &dcc
  }
}

Does anyone have any ideas on what I'm doing wrong?
Posted By: ScatMan

Re: Receiving DCC files through sockets - 27/07/03 10:53 AM

on *:SOCKREAD:dcc.*:{
if ($sockerr) { return }
while ($sock($sockname).rq) {
sockread 4096 &dcc
bwrite %filename -1 -1 &dcc
}
}
Posted By: Rich

Re: Receiving DCC files through sockets - 27/07/03 01:05 PM

The reason the transfer stops is because you're not following the DCC protocol: this requires the receiver to acknowledge all received data by sending back the total number of received bytes.
(see http://www.user-com.undernet.org/documents/dccinfo.html)

Code that should work: (but has not been tested at all)
Code:
on *:SOCKREAD:dcc.*:{
  if ($sockerr) { echo sockerror! | return }
  sockread 4096 &dcc
  while ($sockbr) {
    bwrite %filename -1 -1 &dcc
    sockread 4096 &dcc
  }

  ;get number of received bytes
  var %rcvd = $sock($sockname).rcvd
  ;$longip converts this from decimal to base 256 
  ;  (you could use some complicated $calc with a lot of % 256 but this takes less code)
  ;then replace the dots with spaces, put it in the binvar and send it
  bset &rcvd 1 $replace($longip(%rcvd),.,$chr(32))
  sockwrite $sockname &rcvd
}
Posted By: Rooster74

Re: Receiving DCC files through sockets - 27/07/03 03:53 PM

Thank you, that worked perfectly. I had read in another thread elsewhere that I needed to send an acknowledgement back, but none of the dcc protocal information I could find specified exactly what I needed to send back.
Posted By: Rooster74

Re: Receiving DCC files through sockets - 29/07/03 04:10 AM

One other question I thought of, how can I tell the download speed?
Posted By: Massacre

Re: Receiving DCC files through sockets - 06/11/03 09:04 PM

I am building an app in java that received DCCs but I'm having alot of trouble making mirc understand the msg I'm sending back stating the bytes received. I'm doing the following which I think matches the above: taking the number of bytes written, eg. 4096 and converting it to "shortip" format via a (working) method that returns an IP type number. I then write each section (tokenized by '.') as an Integer to the stream and send. mIRC doesn't like it. I've spent hours trying different methods. Here is an example of what would be written for 4096:

0
0
16
0

Is that right? and if not does anyone know what it should be and how to get there?
Posted By: Rich

Re: Receiving DCC files through sockets - 07/11/03 01:58 PM

You should just send 32 bits specifying how much you received:
If you received 4096 bytes you would send $chr(0) $+ $chr(0) $+ $chr(16) $+ $chr(0)
© 2022 mIRC Discussion Forums