mIRC Home    About    Download    Register    News    Help

Print Thread
sockwrite #208775 28/01/09 04:55 PM
Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
i am trying to send a image through sockets but i get this message when i try:

* /sockwrite: 'pws_122246' queue would exceed 16384 bytes (line 52, pws.mrc)


Code:
      bread $scriptdir $+ Parallel_Dimensions.jpg 1 372874 &bimg
      sockwrite $sockname &bimg
      sockwrite $sockname $crlf
      sockclose $sockname

Re: sockwrite [Re: MTec007] #208777 28/01/09 05:13 PM
Joined: Dec 2002
Posts: 3,138
C
Collective Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
/help on SOCKWRITE

Re: sockwrite [Re: Collective] #208779 28/01/09 05:26 PM
Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
im really not sure what is there that can help me understand how to do this. i know mirc can send this image but i am having a difficult time with it. i even tried doing

bread $scriptdir $+ favicon.ico 0 16384 &bimg
bread $scriptdir $+ favicon.ico 16385 16384 &bimg2

sockwrite $sockname &bimg
sockwrite $sockname &bimg2
etc...


but it still fails.

Last edited by MTec007; 28/01/09 05:28 PM.
Re: sockwrite [Re: MTec007] #208780 28/01/09 05:29 PM
Joined: Dec 2002
Posts: 3,138
C
Collective Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Then you didn't read the help file entry. It describes the exact problem you're experiencing and how to fix it.

Re: sockwrite [Re: Collective] #208781 28/01/09 05:35 PM
Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
im not sure how to use $sock().sq in my code. i have read the help file i just dont know how to use certain things in the script.


edit:

this code sends 99% of the image then fails.


Code:
      bread $scriptdir $+ Parallel_Dimensions.jpg 0 $file($scriptdir $+ Parallel_Dimensions.jpg).size &bimg
      var %start 0, %len 16000
      while ($sock($sockname).sq == 0) {
        sockwrite $sockname &bimg $bvar(&bimg,%start,%len)

        if (%len > $file($scriptdir $+ Parallel_Dimensions.jpg).size) {
          var %len $file($scriptdir $+ Parallel_Dimensions.jpg).size
        }
        else {
          inc %len 16000
        }
        inc %start 16001
      }
      sockwrite $sockname $crlf
      sockclose $sockname

Last edited by MTec007; 28/01/09 05:53 PM.
Re: sockwrite [Re: MTec007] #208782 28/01/09 06:03 PM
Joined: Dec 2002
Posts: 3,138
C
Collective Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
A quick and dirty (and untested) implementation would look like:
Code:
on *:SOCKREAD:sockname:{
  if ( $sockerr ) return
  sockread %temp
  if ( %temp == <request for image> ) {
    sockmark $sockname sending
    set %sendfile filename.jpg
    set %sendpos 0
    sendfilenext
  }
}
on *:SOCKWRITE:sockname:{
  if ( $sockerr ) return
  if ( $sock($sockname).mark == sending ) {
    sendfilenext
  }
}
alias sendfilenext {
  var %queuespace = $calc(16384 - $sock($sockname).sq)
  if ( %queuespace > 0 ) {
    bread %sendfile %sendpos %queuespace &temp
    sockwrite $sockname &temp
    inc %sendpos %queuespace
    if ( %sendpos >= $file(%sendfile).size ) {
      sockmark $sockname
      echo -a Sending of %sendfile complete
    }
  }
}

Re: sockwrite [Re: Collective] #208784 28/01/09 06:14 PM
Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
that works really well! thanks a lot

Re: sockwrite [Re: MTec007] #208787 28/01/09 06:59 PM
Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
edit:

if i receive requests for 2 or more images there is a conflict and the images only get partially sent. how can i avoid the conflict or queue the other images until the one is done?

i think this conflict is with the alias itself but i cant pinpoint it. my sockaccept is as follows so i can do more than one connection at a time:

var %_r = $r(1,500000)
sockaccept pws_ [ $+ [ %_r ] ]

Last edited by MTec007; 28/01/09 10:44 PM.
Re: sockwrite [Re: Collective] #208835 29/01/09 06:48 PM
Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
I am pretty sure now that the problem i am having is when /getfilenext is being run consecutively on two different sockets. any ideas on this problem? (see above for problem)

Re: sockwrite [Re: Collective] #209076 03/02/09 10:35 PM
Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
I've tried many attempts at making this code work when two sockets call files consecutively but i cant get it to. do you know how i would accomplish doing that?

Re: sockwrite [Re: MTec007] #209077 03/02/09 10:52 PM
Joined: Jul 2006
Posts: 3,530
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,530
If you're using Collective's code, it's normal since it has been written to work with one file at time, if you want to be able to send multiple file, you have to change the code in order to have dynamic var, socket name etc...

Last edited by Wims; 03/02/09 10:54 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: sockwrite [Re: MTec007] #209078 03/02/09 10:53 PM
Joined: Dec 2002
Posts: 3,138
C
Collective Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
The script above uses statically-named global variables, so if you're sending two files at once then they'll be modified by two different 'threads' at once.

You can either name the variables dynamically (using $+ and $eval or [ ]), or you can store all the information in the socket mark.

Also it would probably be better to check if your random socket name is taken before /sockaccept'ing to that name.

Re: sockwrite [Re: Collective] #209083 03/02/09 11:14 PM
Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
i tried using this with the vars but the script just silently failed no errors, but nothing happened.

Code:
%var_ [ $+ [ $sockname ] ]

Re: sockwrite [Re: Collective] #209128 04/02/09 08:02 PM
Joined: Feb 2007
Posts: 234
M
MTec007 Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Feb 2007
Posts: 234
how would i utilize sockmark in this instance? i can understand i would use '/sockmark sending $sockname' but past that, it gets a bit foggy for me. in the code below, %queuespace_ [ $+ [ $sockname ] ] returns $null so the 'if ... isnum 1-' fails.

Code:
  var %queuespace_ [ $+ [ $sockname ] ] = $calc(16384 - $sock($sockname).sq)
  if ( %queuespace_ [ $+ [ $sockname ] ] isnum 1- ) {
    bread %sendfile_ [ $+ [ $sockname ] ] %sendpos_ [ $+ [ $sockname ] ] %queuespace_ [ $+ [ $sockname ] ] &temp_ [ $+ [ $sockname ] ]
    sockwrite $sockname &temp_ [ $+ [ $sockname ] ]
    inc %sendpos_ [ $+ [ $sockname ] ] %queuespace_ [ $+ [ $sockname ] ]
    if ( %sendpos_ [ $+ [ $sockname ] ] >= $file(%sendfile_ [ $+ [ $sockname ] ]).size ) {
      sockmark $sockname
      .remove $pws_temp $+ $sockname $+ .tmp
      .remove $pws_temp $+ $sockname $+ _c.tmp
      ;unset %sendfile %sendpos
      .timer 1 1 sockclose $sockname
    }
    ;else { aline @pws 4 %sendpos_ [ $+ [ $sockname ] ] >= $file(%sendfile_ [ $+ [ $sockname ] ]).size   }
  }
  else { aline @pws 4 %queuespace_ [ $+ [ $sockname ] ] isnum 1-  }
}

Last edited by MTec007; 04/02/09 08:35 PM.