mIRC Home    About    Download    Register    News    Help

Print Thread
HTTP 1.1 Image Transfer Issue #204627 26/09/08 02:56 AM
Joined: Sep 2008
Posts: 17
K
Kozical Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Sep 2008
Posts: 17
Hello, I've been using mIRC since the beginning. However I have never really had a need to do what I am doing now. I am trying to make a quick profile preview. I would like the images to display in my dialog.
I connect to the site on port 80 send all the necessary data and get my 200 OK. Then midway through the image transfer it just cuts out. mIRC closes the socket and all is done. The problem is that the file lacked about 2 kilo's of being complete.
I am wondering what can cause this. I've done everything from making my socket -f to actually adding a read size to it. To ensure it's pulling all data possible.
When I Wireshark my browser's navigation to the website all is well. Everything is received fine, When mIRC tries to receive the data it just cuts out. I also investigated whether it was a certain character that cut it off, but to no avail that was not the issue either.

Thanks for the time,
Bryan

Re: HTTP 1.1 Image Transfer Issue [Re: Kozical] #204628 26/09/08 03:04 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Have you tried using HTTP/1.0 ?

-genius_at_work

Re: HTTP 1.1 Image Transfer Issue [Re: genius_at_work] #204630 26/09/08 03:37 AM
Joined: Sep 2008
Posts: 17
K
Kozical Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Sep 2008
Posts: 17
Yes, I have genius. That was also something I tried.

Re: HTTP 1.1 Image Transfer Issue [Re: Kozical] #204632 26/09/08 04:07 AM
Joined: Apr 2008
Posts: 43
Z
zantetsuken Offline
Ameglian cow
Offline
Ameglian cow
Z
Joined: Apr 2008
Posts: 43
no socket errors or anything? maybe try adding a timer to keep the socket open till you're finished then close it after

Re: HTTP 1.1 Image Transfer Issue [Re: zantetsuken] #204633 26/09/08 04:19 AM
Joined: Sep 2008
Posts: 17
K
Kozical Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Sep 2008
Posts: 17
Well Zan, If it were possible to poll for more data. I would do this. I can't see the issue at the moment. I hope it something simple. However as you can see I have resorted to asking my question openly so I have exhausted all my knowledge on the subject. It may just be an error in mIRC. I hope not but that may be the case.

Re: HTTP 1.1 Image Transfer Issue [Re: Kozical] #204634 26/09/08 04:34 AM
Joined: Jul 2006
Posts: 3,568
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,568
You should give your code since it's the only thing that is interesting here, and it's not a mirc problem, rather a script one, so your post should be in Scripts&popups


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: HTTP 1.1 Image Transfer Issue [Re: Wims] #204635 26/09/08 04:41 AM
Joined: Sep 2008
Posts: 17
K
Kozical Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Sep 2008
Posts: 17
Your 'Wim' is my command!

Code:
alias GetProfile {
  var %x = 1, %y = $len($$1), %puid = ""
  while (%x <= %y) {
    %puid = $+(%puid,$base($base($asc($mid($1,%x,1)),10,8),8,16))
    inc %x
  }
  ;if (!$dialog($+(ProfileView.,%puid))) {
  ;  dialog -m $+(ProfileView.,%puid) $+(ProfileView.,%puid)
  ;}
  hadd -m $+(Picture.,%puid) Nickname $1
  sockopen $+(Picture.,%puid) sparkpea.net 80
  ; sockopen $+(Profile.,%puid) sparkpea.net 80
}

on *:SOCKOPEN:Picture.*:{
  sockwrite -n $sockname GET $+(/memberpic.php?size=l&epuid=,$gettok($sockname,2,46)) HTTP/1.0
  sockwrite -n $sockname Host: www.sparkpea.net
  sockwrite -n $sockname $crlf $+ $crlf
}

on *:SOCKREAD:Picture.*:{
  sockread -fn &buffer
  if ($sockerr) {
    echo 5 -s $+(Error in $sockname ",$sock($sockname).wsmsg," [,$sock($sockname).wserr,])
    return
  }
  tokenize 32 $bvar(&buffer,1,$bvar(&buffer,0)).text
  if ($debug()) echo 3 -s $sockname $+ ; $1-

  ;- START SOCKET STATEMENTS

  if ($1 == HTTP/1.1 && $2 != 200) sockclose $sockname
  elseif ($bvar(&buffer,1).long == $null) hadd -m $sockname IsReading $true
  elseif ($hget($sockname,IsReading)) bwrite test.txt -1 -1 &buffer

  ;- END SOCKET STATEMENTS
}

on *:SOCKCLOSE:Picture.*:{
  echo 3 -a SOCKCLOSE $sockname $1-
  if ($findfile($+($ActiveDirectory(),temp\),$+($sockname,.jpg),0)) {
    hadd -m $sockname Picture $+($ActiveDirectory(),temp\,$sockname,.jpg)
    hadd -m $sockname IsReading $false
  }
  else {
    hadd -m $sockname Picture $+($ActiveDirectory(),nophoto.jpg)
    hadd -m $sockname IsReading $false
  }
}

Last edited by Kozical; 26/09/08 04:41 AM.
Re: HTTP 1.1 Image Transfer Issue [Re: Kozical] #204638 26/09/08 02:27 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
It seems that either the server you are pulling the image from is disconnecting the stream, or the method the server is using to redirect you to that image (php) requires some additional programming in the socket.

If I download the image and put it on another server, and then modify the script to work from that server directly (without php redirect) it works just fine everytime.

Strangely, if you compare the two images, on the corrupted image, I get a grey rectangle almost exactly where the "www.sparkpea.net" banner has been inserted into the image. I don't know if that has any significance to the problem or not.


Here is the code I used:


Code:

alias plocal return 1

alias GetProfile {
  var %x = 1, %y = $len($$1), %puid = ""
  while (%x <= %y) {
    %puid = $+(%puid,$base($base($asc($mid($1,%x,1)),10,8),8,16))
    inc %x
  }
  hadd -m $+(Picture.,%puid) Nickname $1

  if ($sock($+(PHeader.,%puid))) sockclose $+(PHeader.,%puid)
  if ($sock($+(PImage.,%puid))) sockclose $+(PImage.,%puid)

  if (!$plocal) sockopen $+(PHeader.,%puid) sparkpea.net 80
  else sockopen $+(PImage.,%puid) ANOTHER.SERVER.COM 80
}

on *:SOCKOPEN:P*.*:{
  echo 3 -a SOCKOPEN $sockname $1-

  if (!$plocal) {
    sockwrite -n $sockname GET $+(/memberpic.php?size=l&epuid=,$gettok($sockname,2,46)) HTTP/1.0
    sockwrite -n $sockname Host: www.sparkpea.net
  }
  else {
    sockwrite -n $sockname GET /path/to/memberpic.jpeg
    sockwrite -n $sockname Host: ANOTHER.SERVER.COM
  }
  sockwrite -n $sockname $crlf $+ $crlf
}

on *:SOCKREAD:PHeader.*:{
  sockread %sread
  if ($sockerr) {
    echo 5 -s $+(Error in $sockname ",$sock($sockname).wsmsg," [,$sock($sockname).wserr,])
    return
  }
  tokenize 32 %sread
  echo -a $sockname > $1-
  if ($1 == HTTP/1.1 && $2 != 200) sockclose $sockname
  if ($len(%sread) == 0) sockrename $sockname $replace($sockname,PHeader,PImage)
}


on *:SOCKREAD:PImage.*:{
  sockread &buffer

  if ($sockerr) {
    echo 5 -s $+(Error in $sockname ",$sock($sockname).wsmsg," [,$sock($sockname).wserr,])
    return
  }

  ;tokenize 32 $bvar(&buffer,1,$bvar(&buffer,0)).text
  ;echo -a $sockname > $1-

  bwrite test.jpg -1 -1 &buffer

}

on *:SOCKCLOSE:PImage.*:{
  echo 3 -a SOCKCLOSE $sockname $1-
}



Change the plocal alias to 0 for the sparkpea server, and to 1 for your secondary server.

-genius_at_work

Re: HTTP 1.1 Image Transfer Issue [Re: genius_at_work] #204659 26/09/08 10:04 PM
Joined: Sep 2008
Posts: 17
K
Kozical Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Sep 2008
Posts: 17
Nice Job, Genius. Definitely turned out better than mine did. Mine were turning out with a lot more distorted pixels. I believe i can work with this. You did a fine job, /me hands you a cookie. Heh, you earned your title today. So good on ya. cool

Thanks again everyone, for the time and efforts.

Bryan