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)
bread $scriptdir $+ Parallel_Dimensions.jpg 1 372874 &bimg
sockwrite $sockname &bimg
sockwrite $sockname $crlf
sockclose $sockname
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.
Then you didn't read the help file entry. It describes the exact problem you're experiencing and how to fix it.
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.
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
A quick and dirty (and untested) implementation would look like:
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
}
}
}
that works really well! thanks a lot
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 ] ]
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)
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?
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...
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.
i tried using this with the vars but the script just silently failed no errors, but nothing happened.
%var_ [ $+ [ $sockname ] ]
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.
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- }
}