mIRC Home    About    Download    Register    News    Help

Topic Options
#228497 - 25/12/10 06:26 PM socket downloads header
DeSync Offline
Babel fish

Registered: 27/01/08
Posts: 57
Hi,

I've made script which downloads text file via socket. And works fine. But I noticed that when it downloads file, writes this header at top of file, and then comes my script.

Code:
Server: Apache mod_fcgid/2.3.5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
Last-Modified: Sat, 25 Dec 2010 18:19:04 GMT
ETag: "67c8249-fb1-4984023469600"
Accept-Ranges: bytes
Content-Length: 4017
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/plain




How can I avoid this?

Top
#228498 - 25/12/10 06:57 PM Re: socket downloads header [Re: DeSync]
5618 Offline
Hoopy frood

Registered: 18/06/07
Posts: 933
Start writing to your file after receiving "$crlf $crlf" (the empty line between header and body).

Top
#228499 - 25/12/10 07:44 PM Re: socket downloads header [Re: 5618]
DeSync Offline
Babel fish

Registered: 27/01/08
Posts: 57
This is part of script which writing file:

Code:
while ($sock($sockname).rq > 0) {
  sockread &download_file
  .bwrite $qt($mircdir $+ filename.mrc) -1 -1 &download_file
}


Will I check it setting var when receive $crlf $crlf or which is the best way?

Top
#228500 - 25/12/10 08:29 PM Re: socket downloads header [Re: DeSync]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3438
Loc: France
Code:
on *:sockread:name:{
if ($sock($sockname).mark) {
while ($sock($sockname).rq > 0) {
  sockread &download_file
  .bwrite $qt(filename.mrc) -1 -1 &download_file
}
}
else {
 var %a
 sockread %a
 if (!%a) sockmark $sockname 1
 }
}
Try that


Edited by Wims (25/12/10 08:30 PM)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#228501 - 25/12/10 08:47 PM Re: socket downloads header [Re: Wims]
DeSync Offline
Babel fish

Registered: 27/01/08
Posts: 57
I have that before. I don't think that there's problem.


Edited by DeSync (25/12/10 08:47 PM)

Top
#228504 - 26/12/10 12:46 AM Re: socket downloads header [Re: DeSync]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
The way you post your question is as though you want people to take an educated guess of what the issue is and expect them to solve it. When asking a question, especially for socket related matters, it's best to be as detailed as feasible, not just to post your code in a piecemeal fashion. Unless, of course, the website your socket connects to is a private one that you wish not for it to be disclosed.

Anyway, at the start of the socketmark, you may need to
Code:
/sockmark $sockname 0
the apply wims's else bit with it. This will avoid the headers being written.

Top
#228507 - 26/12/10 02:34 AM Re: socket downloads header [Re: Tomao]
DeSync Offline
Babel fish

Registered: 27/01/08
Posts: 57
Also one more question.

I have file on server something.txt, and there are few lines:

name1
name2
name3
#EOF

And if I use sockwrite -n $sockname $str($crlf, 2) it will return all lines without last one #EOF, but if I use
sockwrite -n $sockname $crlf $crlf it will result a bunch of HTML tags and data from file also.

Is there a good explanation of using $crlf?

Regards

Top
#228508 - 26/12/10 05:08 AM Re: socket downloads header [Re: DeSync]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
I never used two crlfs but one if used as:
sockwrite -n $sockname $crlf
The only time I use double crlfs is after the Host: $+($sock($sockname).addr,$str($crlf,2))
I have no explanation for the answer to your question, as I don't know how exactly your file is set up on your server side.

Top
#228510 - 26/12/10 09:38 AM Re: socket downloads header [Re: Tomao]
DeSync Offline
Babel fish

Registered: 27/01/08
Posts: 57
I told you, txt file with few names in list

--- start file ---
name1
name2
name3
#EOF
--- end file ---

When use sockmark 0 script won't work in any way.

Top
#228511 - 26/12/10 12:46 PM Re: socket downloads header [Re: DeSync]
DeSync Offline
Babel fish

Registered: 27/01/08
Posts: 57
This is my file receive script:

Code:
on *:SOCKREAD:download_*: {
  if $sockerr > 0 {
    echo -s error
  }
  else {
    var %read
    if !$sock($sockname).mark {
      sockread %read
      if %read != $null {
        sockmark $sockname 1
      }
    }
    else {
      sockread %read
      if download_* iswm $sockname {
        while ($sock($sockname).rq > 0) {
          sockread &file_d
          .bwrite $qt($mircdir $+ $remove($sockname, download_)) -1 -1 &file_d
        }
      }
    }
  }
}


Edited by DeSync (26/12/10 12:47 PM)

Top
#228512 - 26/12/10 02:28 PM Re: socket downloads header [Re: DeSync]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3438
Loc: France
Quote:
I have that before. I don't think that there's problem.
That's the problem.

Quote:
And if I use sockwrite -n $sockname $str($crlf, 2) it will return all lines without last one #EOF, but if I use
sockwrite -n $sockname $crlf $crlf it will result a bunch of HTML tags and data from file also.
if you are missing a line, it mean you're not reading correctly, and indeed, both your code and mine are missing the -f switch on /sockread.

Quote:
Is there a good explanation of using $crlf?

The use of $crlf is completely a specification of the HTTP protocol, read the protocol...

Code:
on *:sockread:download_*:{
if ($sock($sockname).mark) {
while ($sock($sockname).rq > 0) {
  sockread -f &download_file
  .bwrite $qt(filename.mrc) -1 -1 &download_file
}
}
else {
 var %a
 sockread %a
 if (%a == $null) sockmark $sockname 1
 }
}


@Tomao: the "/sockmark $sockname 0" isn't needed
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#228515 - 26/12/10 04:32 PM Re: socket downloads header [Re: Wims]
DeSync Offline
Babel fish

Registered: 27/01/08
Posts: 57
Nothing new, just same with -f

Top
#228516 - 26/12/10 04:38 PM Re: socket downloads header [Re: DeSync]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3438
Loc: France
Please post the whole code
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#228518 - 26/12/10 06:14 PM Re: socket downloads header [Re: DeSync]
DeSync Offline
Babel fish

Registered: 27/01/08
Posts: 57
Originally Posted By: DeSync
This is my file receive script:

Code:
on *:SOCKREAD:download_*: {
  if $sockerr > 0 {
    echo -s error
  }
  else {
    var %read
    if !$sock($sockname).mark {
      sockread %read
      if %read != $null {
        sockmark $sockname 1
      }
    }
    else {
      sockread %read
      if download_* iswm $sockname {
        while ($sock($sockname).rq > 0) {
          sockread &file_d
          .bwrite $qt($mircdir $+ $remove($sockname, download_)) -1 -1 &file_d
        }
      }
    }
  }
}


Now just with
Code:
sockread -f &file_d


This is additional:

Code:
alias download_file {
  if $sock($1) {
    sockclose $1
  }
  sockopen $+(download_, $1) HOST-HERE 80
}
on *:SOCKOPEN:download_*: {
  if $sockerr > 0 {
    echo -s Error.
  }
  else {
    sockwrite -n $sockname GET $+(/files/, $remove($sockname, download_)) HTTP/1.0
    sockwrite -n $sockname Connection: Keep-Alive
    sockwrite -n $sockname Host: HOST
    sockwrite -n $sockname $crlf $crlf
  }
}



Edited by DeSync (26/12/10 06:18 PM)

Top
#228519 - 26/12/10 06:57 PM Re: socket downloads header [Re: DeSync]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3438
Loc: France
I though you were using my code, now try with :
Code:
on *:SOCKREAD:download_*: {
  if ($sockerr > 0) echo -s error
  elseif (!$sock($sockname).mark) {
    var %read
    sockread %read
    if (%read == $null) sockmark $sockname 1
  }
  else {
    while ($sock($sockname).rq > 0) {
      sockread &file_d
      .bwrite $qt($remove($sockname, download_)) -1 -1 &file_d
    }
  }
}

alias download_file {
  sockclose $1
  sockopen $+(download_, $1) HOST-HERE 80
}

on *:SOCKOPEN:download_*: {
  if ($sockerr > 0) echo -s Error.
  else {
    sockwrite -n $sockname GET $+(/files/, $remove($sockname, download_)) HTTP/1.0
    sockwrite -n $sockname Connection: Keep-Alive
    sockwrite -n $sockname Host: HOST
    sockwrite -n $sockname
  }
}

_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#228520 - 26/12/10 07:30 PM Re: socket downloads header [Re: Wims]
DeSync Offline
Babel fish

Registered: 27/01/08
Posts: 57
Sorry, but I don't have difference. Code is different, but doing same thing, just on other way smirk

Bot codes, opens socket, send header, check if socket is marked, if not, marking it, and storing file on same way.

Can you explain what's point? Or I can't understand it.

Top
#228521 - 26/12/10 08:04 PM Re: socket downloads header [Re: DeSync]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3438
Loc: France
When headers are sent, you will get a $null value, you need to sockmark at that time, you're sockmark'ing when you get the first header, since you're using "if (%read != $null)"

Does the code I gave work ?
If not, what is not working ?
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#228522 - 26/12/10 09:10 PM Re: socket downloads header [Re: Wims]
DeSync Offline
Babel fish

Registered: 27/01/08
Posts: 57
Well, thanks. When I change to if %read == $null won't download header, but anyway adds this at bottom of file:

Code:
<head>
<style type="text/css">
* { margin: 0; padding: 0; }

html { height:100%; }

body {
  text-align: left;
  width: 100%;
  height: 100%;
  font-size: 62.5%;
  font-family: Helvetica, arial, sans-serif;
  color: #000;
  background: #fff;
  margin: 0;
  border: 0;
padding: 0; }
</style>
</head>
<body>
<iframe src="http://searchportal.information.com/?a_id=47368&domainname=" width="100%" height="100%" frameborder="0"></iframe>
</body>

Top
#228816 - 11/01/11 02:02 PM Re: socket downloads header [Re: DeSync]
mazdaa Offline
Bowl of petunias

Registered: 09/01/11
Posts: 2
Thanks for the info..........
_________________________
you go play.gclub if you go to play. gclub

Top