mIRC Home    About    Download    Register    News    Help

Print Thread
mIRC website o_O #132910 15/10/05 05:55 PM
Joined: Mar 2004
Posts: 14
A
Axodious Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Mar 2004
Posts: 14
A couple of my friends turned mirc into a fully functional text webserver using sockets, they asked me if there is a way using sockwrite to display images too. I can't seem to find a way so I decided to post here maybe someone else has done it before. I can't post anycode as its not mine to post but does anyone have an idea of how to send images (gif to be exact) through sockwrite to a web browser? confused

Re: mIRC website o_O #132911 15/10/05 07:44 PM
Joined: Jun 2005
Posts: 11
H
hantu Offline
Pikka bird
Offline
Pikka bird
H
Joined: Jun 2005
Posts: 11
Hello,

I'm not 100% sure about this, just my thought..

You can /bread from the actual file, and sockwrite the binary variable you got to the socket connection..

I'm not sure, sorry ^^:


- hantu
Re: mIRC website o_O #132912 16/10/05 08:29 PM
Joined: Mar 2004
Posts: 14
A
Axodious Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Mar 2004
Posts: 14
Didn't work. Could this possibly be one of those extremely rare mIRC limitations? shocked

Re: mIRC website o_O [Re: Axodious] #199568 16/05/08 04:16 PM
Joined: Mar 2006
Posts: 5
X
xLadyHawkx Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
X
Joined: Mar 2006
Posts: 5
The problem with this was the fact that mirc would try and display the link to the local picture on the hard drive which was not available to someone accessing the link to the mirc generated page. It would only work with pictures already on the internet somewhere, but with mirc being used AS the webhost, i didn't want to need another webhost just for the images.

Never figured out a way to get around that, but in the end i did have a nice 3 page mirc generated systeminfo website, and only 1 script file to show it. Without pictures frown

I had some fun with that, thinking about how people access a non-existant page which an irc client that wrote it on the spot.

Re: mIRC website o_O [Re: xLadyHawkx] #199569 16/05/08 05:16 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
You would have to listen for requests in your on sockread event to check if the client has requested an image and if so, read that file using /bread and then send it over the socket.

You can't just send the contents of the file though, you have to send a header to tell the client what you're sending so that it knows what to do with the data.

Google "HTTP rfc" and swat up on the HTTP protocol.

Re: mIRC website o_O [Re: hixxy] #199571 16/05/08 06:02 PM
Joined: Mar 2004
Posts: 14
A
Axodious Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Mar 2004
Posts: 14
Originally Posted By: hixxy
You would have to listen for requests in your on sockread event to check if the client has requested an image and if so, read that file using /bread and then send it over the socket.

You can't just send the contents of the file though, you have to send a header to tell the client what you're sending so that it knows what to do with the data.

Google "HTTP rfc" and swat up on the HTTP protocol.


How would I output this via a socket, everyway I've tried has given me either "Line too long" or "queue would exceed 16384 bytes"

Re: mIRC website o_O [Re: Axodious] #199572 16/05/08 06:19 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
Read 8192 bytes from the file, send it with /sockwrite, then read the next 8192 bytes, and so on. Don't try sending the entire file in one /sockwrite.

Re: mIRC website o_O [Re: hixxy] #199579 16/05/08 07:42 PM
Joined: Mar 2004
Posts: 14
A
Axodious Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Mar 2004
Posts: 14
Here is a little snippet of code I've been using as a test (please ignore my poor/messy scripting):

elseif ($1 == GET) && ($2 == /banner.gif) {
set -u0 %ghanakingif1 0
set -u0 %ghanakingif2 $file(banner.gif).size
while (%ghanakingif1 < %ghanakingif2) {
bread banner.gif %ghanakingif1 8192 &test $+ %ghanakingif1
sockwrite $sockname &test $+ %ghanakingif1
set -u0 %ghanakingif1 $calc(%ghanakingif1 + 8192)
}
}

If I use a small image (8192 or smaller basicly) it works absolutly fine, however if I use a larger image I get random results. Sometimes no errors in mIRC but only a piece of the image displays. Sometimes the same thing but with the "queue would exceed 16384 bytes" error.

Re: mIRC website o_O [Re: Axodious] #199584 16/05/08 08:50 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
You can't just loop through it like that because you're not giving it time to be sent. You should use the on sockwrite event to know when to send each new chunk. Even then you should check $sock($sockname).sq + the length of data you're sending doesn't exceed 16384 bytes, otherwise wait until the next sockwrite event.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: mIRC website o_O [Re: starbucks_mafia] #199617 17/05/08 04:16 PM
Joined: Jan 2004
Posts: 162
R
RRX Offline
Vogon poet
Offline
Vogon poet
R
Joined: Jan 2004
Posts: 162
Raises a question, I think I remember in the past that the on sockwrite event triggered when the socket buffer became empty, now the help file has besides that also 'or when the socket is ready to send more data'.
How should this be interpreted?
If the socket buffer is empty, doesn't that imply it is ready for new data?
What exactly is this 'socket ready' status?
I've seen a script that uses a high resolution timer which calls an alias that checks $sock().sq and fill it completely as soon as there is 1 byte free (difference between max and .sg), it was claimed as alot faster. To me that appears rather excessive performance wasting (aka very bad efficiency) though.

Another thing is that $sockerr check. Some scripters have a loop inside on SOCKREAD which check $sockerr every iteration. I thought $sockerr was set upon event triggering, and can't change during the execution of the event, and also that during that execution time it can't have data in the socket buffer that wasn't there at the moment the on SOCKREAD was triggered.

Or is the OS able to fill the socket buffer (I read that it's stored in memory allocated to mIRC) while mIRC (singlethreaded) is busy executing the on SOCKREAD script code?