|
Joined: Jan 2008
Posts: 57
Babel fish
|
OP
Babel fish
Joined: Jan 2008
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. 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?
|
|
|
|
Joined: Jun 2007
Posts: 933
Hoopy frood
|
Hoopy frood
Joined: Jun 2007
Posts: 933 |
Start writing to your file after receiving "$crlf $crlf" (the empty line between header and body).
|
|
|
|
Joined: Jan 2008
Posts: 57
Babel fish
|
OP
Babel fish
Joined: Jan 2008
Posts: 57 |
This is part of script which writing file: 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?
|
|
|
|
Joined: Jul 2006
Posts: 4,103
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,103 |
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
Last edited by Wims; 25/12/10 08:30 PM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2008
Posts: 57
Babel fish
|
OP
Babel fish
Joined: Jan 2008
Posts: 57 |
I have that before. I don't think that there's problem.
Last edited by DeSync; 25/12/10 08:47 PM.
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
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 the apply wims's else bit with it. This will avoid the headers being written.
|
|
|
|
Joined: Jan 2008
Posts: 57
Babel fish
|
OP
Babel fish
Joined: Jan 2008
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
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
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.
|
|
|
|
Joined: Jan 2008
Posts: 57
Babel fish
|
OP
Babel fish
Joined: Jan 2008
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.
|
|
|
|
Joined: Jan 2008
Posts: 57
Babel fish
|
OP
Babel fish
Joined: Jan 2008
Posts: 57 |
This is my file receive script: 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
}
}
}
}
}
Last edited by DeSync; 26/12/10 12:47 PM.
|
|
|
|
Joined: Jul 2006
Posts: 4,103
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,103 |
I have that before. I don't think that there's problem. That's the problem. 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. Is there a good explanation of using $crlf? The use of $crlf is completely a specification of the HTTP protocol, read the protocol... 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
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2008
Posts: 57
Babel fish
|
OP
Babel fish
Joined: Jan 2008
Posts: 57 |
Nothing new, just same with -f
|
|
|
|
Joined: Jul 2006
Posts: 4,103
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,103 |
Please post the whole code
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2008
Posts: 57
Babel fish
|
OP
Babel fish
Joined: Jan 2008
Posts: 57 |
This is my file receive script: 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 This is additional: 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
}
}
Last edited by DeSync; 26/12/10 06:18 PM.
|
|
|
|
Joined: Jul 2006
Posts: 4,103
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,103 |
I though you were using my code, now try with :
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
}
}
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2008
Posts: 57
Babel fish
|
OP
Babel fish
Joined: Jan 2008
Posts: 57 |
Sorry, but I don't have difference. Code is different, but doing same thing, just on other way  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.
|
|
|
|
Joined: Jul 2006
Posts: 4,103
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,103 |
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 ?
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2008
Posts: 57
Babel fish
|
OP
Babel fish
Joined: Jan 2008
Posts: 57 |
Well, thanks. When I change to if %read == $null won't download header, but anyway adds this at bottom of file: <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>
|
|
|
|
Joined: Jan 2011
Posts: 2
Bowl of petunias
|
Bowl of petunias
Joined: Jan 2011
Posts: 2 |
Thanks for the info..........
you go play. gclub if you go to play. gclub
|
|
|
|
|