mIRC Homepage
Posted By: TillableToast Having trouble with sockets - 21/05/16 02:28 AM
Hi so I have recently been messing around with sockets though it doesn't work. I get the error message: /sockwrite: 'GET' no such socket (line 36, remote.ini)

I would very much like to get some help thank you!

on *:TEXT:!connect:#magnusgameplay:{
sockopen Test thefaaborg.dk 80
}

on *:SOCKOPEN:Test: {
sockwrite -nt $RSplay GET /protocal.html
sockwrite -nt $RSplay Host: thefaaborg.dk
sockwrite $RSplay $crlf
}

on *:SOCKREAD:Test: {
if (!$sockerr) {
var %sockreader
sockread %sockreader
if (For mig har chatten* iswm %sockreader) {
tokenize 32 %sockreader
Test $4
sockclose Test
}
}
}
Posted By: OrFeAsGr Re: Having trouble with sockets - 21/05/16 02:39 AM
Hey your script looks mostly fine! Good job!
What is $RSplay supposed to return?
There should be a socket name where it is. But because it doesnt return anything mirc sees GET as the socket name and returns error cause there is not such socket! Why dont you use $sockname ? smile
Posted By: TillableToast Re: Having trouble with sockets - 21/05/16 02:45 AM
Thanks for the quick reply, Im trying to setup a system that let's people request to get my Chat bot connected to their twitch chat via external website, though i'm not having any luck. I have changed everything to be $Test but no luck thus far.
Posted By: OrFeAsGr Re: Having trouble with sockets - 21/05/16 02:50 AM
No problem! smile
The socket name is returned by $sockname idenitifier.
In your script the socket name is Test so you can either use Test or $sockname .
Posted By: TillableToast Re: Having trouble with sockets - 21/05/16 02:51 AM
So how should my script look? I don't quite get it. Sorry for the inconvenience
Posted By: OrFeAsGr Re: Having trouble with sockets - 21/05/16 03:03 AM
Because you write stuff to the socket you have opened, after "sockwrite -nt " ,which the command that writes to socket , you must use $sockname
The sockopen command doesnt need the $sockname identifier after it because it opens the socket you want. In your case "test"
So to open the sockname as you did at original script
Code:
 
sockopen Test thefaaborg.dk 80 

And to write to the socket
Code:
sockwrite -nt $sockname <stuff here>

Also sockclose needs $sockname after it.
Code:
sockclose $sockname

P.S just to be clear: $sockname returns the name of the socket. That eans that whatever the name of the socket is it will take the place of $sockname as am argument.
Example: just like $nick returns the name of the user that triggers the on text event
Posted By: TillableToast Re: Having trouble with sockets - 21/05/16 03:08 AM
But now it just doen't do anything once i excecute it
Posted By: OrFeAsGr Re: Having trouble with sockets - 21/05/16 03:17 AM
Try sending me the code as it is now smile
Posted By: TillableToast Re: Having trouble with sockets - 21/05/16 03:19 AM
on *:TEXT:!connect:#magnusgameplay:{
sockopen Test thefaaborg.dk 80
}

on *:SOCKOPEN:Test: {
sockwrite -nt $sockname GET /protocal.html
sockwrite -nt $sockname Host: thefaaborg.dk
sockwrite $sockname $crlf
}

on *:SOCKREAD:Test: {
if (!$sockerr) {
var %sockreader
sockread %sockreader
if (For mig har chatten* iswm %sockreader) {
tokenize 32 %sockreader
Test $4
; Im trying to make it excecute a command here based on $4
sockclose Test
}
}
}
Posted By: OrFeAsGr Re: Having trouble with sockets - 21/05/16 03:25 AM
Have you made an alias test? Maybe there is something wrong in that alias. Can i see it?
Also try adding
Code:
echo -a %sockreader

After the line you use sockread.that way you'll see if the page is written correctly/the connection is made proeprly.
Posted By: TillableToast Re: Having trouble with sockets - 21/05/16 03:30 AM
This is the alias:
alias Test {
msg # test
}

It doesn't display anything once added the echo

on *:SOCKREAD:Test: {
if (!$sockerr) {
var %sockreader
sockread %sockreader
if (For mig har chatten* iswm %sockreader) {
tokenize 32 %sockreader
echo -a %sockreader
sockclose Test
}
}
}
Posted By: OrFeAsGr Re: Having trouble with sockets - 21/05/16 03:39 AM
Ok so in the alias if you want to use the first parameter you need $1 and not #
(# returns the channel name in events such as on text, on join etc.)
So for example an alias works this way: if you do
test glass wood iron

In the alias test
$1 will return glass
$2 will return wood
$3 will return iron
And so on..
So try msg $1 test

And also what i meant was using echo before the if and after the sockread! That way everthing will be printed to the active window
EDIT: CORRECTED EXAMPLE (sorry i'm sleepy :p)
Posted By: TillableToast Re: Having trouble with sockets - 21/05/16 03:46 AM
It still does not return anything, I'm kinda noobie at mirc so maybe sockets just ain't for me BUT I need to get it working otherwise I can't use the bot for anything

on *:SOCKREAD:Test: {
echo -a %sockreader
if (!$sockerr) {
var %sockreader
sockread %sockreader
if (For mig har chatten* iswm %sockreader) {
tokenize 32 %sockreader

sockclose Test
}
echo -a %sockreader
}
}
Posted By: TillableToast Re: Having trouble with sockets - 21/05/16 03:59 AM
Hmmh seems as though I got it to work! now I just can't seem to take the thefaaborg magnusgameplay tillableToast and pick one of them using $2

on *:SOCKREAD:Test: {
if (!$sockerr) {
var %sockreader
sockread %sockreader
if (thefaaborg magnusgameplay tillableToast iswm %sockreader) {
tokenize 32 %sockreader
echo $2 (This right here should display magnusgameplay)
sockclose Test
}
}
}
Posted By: OrFeAsGr Re: Having trouble with sockets - 21/05/16 04:05 AM
TillableToast is in a different line and you tokenize the reader so you can make it:
Code:
if ($1-2 == thefaaborg magnusgameplay) {

The rest is fine
Posted By: TillableToast Re: Having trouble with sockets - 21/05/16 04:10 AM
But what I want to do is to make it to a user clicks "Connect Bot" on my website (I have it hooked up to Twitch API) so that it then sends the Twitch username to the bot, so it knows what channel to connect to. So my idea was to make their twitch name appear in the HTML file, so that I then could grab it using the %socketreader
Posted By: OrFeAsGr Re: Having trouble with sockets - 21/05/16 04:18 AM
$2 will return the channel nam , you can do
join $2
In the if i told you and the bot will join!
On HTML i have no advices cause i dont know much.
I'll be back later! Need sleep! Cya!
© mIRC Discussion Forums