mIRC Home    About    Download    Register    News    Help

Print Thread
Server response takes long #251791 03/03/15 11:10 PM
Joined: Mar 2014
Posts: 42
S
Sjoepele Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
Hi, i was doodling around with an alias that creates a click to tweet link, and although it does work, it takes up to 15 seconds for me to receive a response from the server. So i was wondering if anyone notices anything wrong/missing from my script that causes that

Code:
alias newTweet {
  set %tweetmsg tweet= $+ $urlencode($1-) $+ &submit=Generate+New+Link
  sockclose newTweet
  sockopen -e newTweet clicktotweet.com 443
}

on *:sockopen:newTweet:{
  if ($sockerr) { return }
  sockwrite -n $sockname POST /link/basicSubmit? $+ %tweetmsg HTTP/1.1
  sockwrite -n $sockname Host: clicktotweet.com
  sockwrite -n $sockname Content-Length: $len(%tweetmsg)
  sockwrite -n $sockname Connection: close
  sockwrite -n $sockname $crlf
}

on *:sockread:newTweet:{
  var %tweetread
  sockread -f %tweetread
  write tweetread.txt %tweetread
}

on *:sockclose:newTweet:{
  var %tweetID = $remove($read(tweetread.txt,9),location: /basic/)
  echo -s Acquired response from server: www.clicktotweet.com/ $+ %tweetID
  unset %tweetmsg
  remove tweetread.txt
}

alias UrlEncode return $regsubex($1-,/([^\d\w])/g,$+(%,$base($asc(\t),10,16)))


If you see anything off (apart from my easymode sockread event) please let me know!

Re: Server response takes long [Re: Sjoepele] #251792 03/03/15 11:33 PM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Well try use COM method it is a kind fast than sockets, try use this code:

Usage: //echo is $clicktotweet(test message)

Code:
alias -l urlencode { return $regsubex($$1-,/([^\d\w])/g,$+(%,$base($asc(\t),10,16))) }
alias clicktotweet {
  if (!$1) { return }
  var %url https://clicktotweet.com/link/basicSubmit?tweet= $+ $urlencode($1-) $+ &submit=Generate+New+Link
  var %com = click_ $+ $ticks $+ $ctime
  .comopen %com msxml2.xmlhttp 
  noop $com(%com, Open,1, bstr,GET,bstr,%url,bool,false) $com(%com,Send,1) $com(%com,ResponseText,2)
  var %a = $remove($com(%com).result,$chr(10),$chr(9),$chr(13))
  var %a = $gettok($wildtok(%a,*http://ctt.ec/*,$wildtok(%a,*http://ctt.ec/*,0,32),32),2,34)
  if ($comerr) { return 0 }
  if ($com(%com)) { .comclose %com }
  return %a
}


Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-
Re: Server response takes long [Re: westor] #251793 04/03/15 12:01 AM
Joined: Mar 2014
Posts: 42
S
Sjoepele Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
Holy cow that is so much faster o_O thank you so much!
I guess i should learn more about this com function shocked

okay this com thing is waaaay out of my league. I cant even seem to decode what that code is doing lol.

I wonder why the socket was slow though, because im fairly confident it wasnt the actual socket that was slow, but more likely something i forgot/messed up.

Last edited by Sjoepele; 04/03/15 12:32 AM.
Re: Server response takes long [Re: Sjoepele] #251828 05/03/15 07:34 PM
Joined: Jul 2006
Posts: 3,745
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,745
You are using /write inside the on sockread event, each time you call /write it has to open the file, write the content and then closr the file.
Whereas you could open the file once, write the data, and close it once inside the on sockclose event, this is most likely the issue here.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Server response takes long [Re: Sjoepele] #251840 06/03/15 01:11 PM
Joined: Jul 2006
Posts: 3,745
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,745
Also, the on socckread event is reading (in a wrong way but let's assume it's correct) line by line, which is much slower than reading everything at once, you don't need to read line by line:

Code:
 on *:sockopen:newTweet:{
 if ($sockerr) { return }
  sockwrite -n $sockname POST /link/basicSubmit? $+ %tweetmsg HTTP/1.1
  sockwrite -n $sockname Host: clicktotweet.com
  sockwrite -n $sockname Content-Length: $len(%tweetmsg)
  sockwrite -n $sockname Connection: close
  ;-n already sends a $crlf if the data you send doesn't end with a $crlf
  sockwrite -n $sockname
  .fopen -o newtweet tweetread.txt
}

on *:sockread:newTweet:{
  if ($sockerr) {
    .fclose newtweet
    return
  }
  sockread $sock(newtweet).rq &a
  .fwrite -b newtweet &a
}

on *:sockclose:newTweet:{
  .fclose newtweet
  var %tweetID = $remove($read(tweetread.txt,9),location: /basic/)
  echo -s Acquired response from server: www.clicktotweet.com/ $+ %tweetID
  unset %tweetmsg
  remove tweetread.txt
}


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Server response takes long [Re: Wims] #251841 06/03/15 01:24 PM
Joined: Dec 2013
Posts: 779
N
Nillen Offline
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
This is very useful info, thank you Wims.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net