mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2003
Posts: 9
D
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Nov 2003
Posts: 9
I want to make something like the DCC but with sockets
how can i do it ?

for example User1 connects to User2 and send a file which User2 want

Joined: Nov 2003
Posts: 227
H
Fjord artisan
Offline
Fjord artisan
H
Joined: Nov 2003
Posts: 227
Should be pretty easy to make, I would use fopen to open files that I was sending and $fread to read the file and store in a binary &variable , you can specify with $fread how many bytes you want to read from a file, this will be like the packet size for your upload, all the protocols like mIRCs built in DCC send can be done via the irc server, meaning that all you have to send via the sockets is the files, on the client side they would be using /bwrite to write to their file all the data coming from the socket, when the tranfer is complete on the sender/servers side close the socket and that will tell the client that the transfer is complete, you will need to use on *:sockwrite so you know when to write to the socket, otherwise the queue would be too great for any file of any size.
It will be a good idea to keep the sockname the same as the name you used to fopen the file then you can just have somethine like.
Code:
 
on *:sockwrite:name*:{
  if ($ferr) { return }
  .echo -q $fread($sockname,1024,&var) 
  sockwrite $sockname &var 
  if ($feof) { 
    .fclose $sockname
    sockclose $sockname
  }
}
 

the $feof means that you have reached the end of the file, then it closed the socket and the file. the example is using 1024 byte packet size. You will need to make lots more than the example part that i showed you above, you will need to establish the connection and write the first packet when its open, then the on sockwrite will take care of most of the rest,
It is a very good idea to use the same socket name as the fopen name though.



Link Copied to Clipboard