mIRC Home    About    Download    Register    News    Help

Print Thread
/socklisten #48080 08/09/03 07:54 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
i dont really get this, if i were to socklisten on port 6667, would this mean that if someone opens a socket to my ip, it would allow me to accept the connection in the on socklisten event?


new username: tidy_trax
Re: /socklisten #48081 08/09/03 07:56 PM
Joined: Jun 2003
Posts: 242
R
r0ck0 Offline
Fjord artisan
Offline
Fjord artisan
R
Joined: Jun 2003
Posts: 242
it would listen for connections on port 6667 yes

Re: /socklisten #48082 08/09/03 08:00 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
is there a way to see whats trying to connect?
also, is there a way that someone can /sockwrite to my ip, and i can see what they /sockwrite'ed?


new username: tidy_trax
Re: /socklisten #48083 08/09/03 08:29 PM
Joined: Mar 2003
Posts: 1,271
L
LocutusofBorg Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
If you detect someone trying to connect to a certain port you are listening on via /socklisten, you can accept the connection with /sockaccept, after which the $sock identifier becomes available to give you information.


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
Re: /socklisten #48084 08/09/03 08:29 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
do you know about my 2nd question?
also, if someone opens a socket to my ip using port 6667, will that use 6667 on my comp as well?
im trying to make a server :tongue:


new username: tidy_trax
Re: /socklisten #48085 09/09/03 04:24 AM
Joined: Mar 2003
Posts: 1,271
L
LocutusofBorg Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
I have never tried anything like that yet, but I imagine it would have to use the on sockread event the trigger when data is received through the socket, in which you /sockread the data and do whatever you want with it.
Also, someone else using a mIRC socket can just /sockwrite to the socket...

Last edited by LocutusofBorg; 09/09/03 05:37 AM.

DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
Re: /socklisten #48086 09/09/03 12:44 PM
Joined: Dec 2002
Posts: 124
B
bloupx Offline
Vogon poet
Offline
Vogon poet
B
Joined: Dec 2002
Posts: 124
if you do /sockaccept it'll use a random free port as specified in mirc dcc options.
and you can check for who's connecting by checking for $sock($sockname).ip in the socklisten event.

Re: /socklisten #48087 09/09/03 04:13 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
thats the problem, i managed to get 16 people to connect, they all tried using /sockwrite and i didnt receive any message, i tried using on sockwrite and on sockread.


new username: tidy_trax
Re: /socklisten #48088 09/09/03 04:47 PM
Joined: Dec 2002
Posts: 117
R
Rich Offline
Vogon poet
Offline
Vogon poet
R
Joined: Dec 2002
Posts: 117
Code:
;open listening socket
alias startlisten socklisten listensocket 6667
;close listening socket
alias stoplisten sockclose listensocket
;close all accepted connections
alias closeall sockclose acceptsock*

;wait for incoming connections
on *:socklisten:listensocket:{
  if ($sockerr) { echo listenerror! | return }
  ;generate unique name
  var %name = acceptsocket $+ $ticks
  ;accept connection
  sockaccept %name
  ;use $sock to retreive info
  echo accepted connection from $sock(%name).ip
}

;wait for incoming data (note the wildcard, it will respond to any socket opened in the ON SOCKLISTEN)
on *sockread:acceptsock*:{
  if ($sockerr) { echo readerror! | return }
  echo Received data from $sock(%name).ip :
  ;read data
  sockread %line
  ;check if any data was read
  while ($sockbr) {
    ;echo data, and check for empty line
    echo $iif(%line,$ifmatch,[empty line])
    ;read next line
    sockread %line
  }
}

Now if you type /startlisten, people should be able to connect to you on port 6667 and any data they send will be echoed.

Note that is just the idea, and far from perfect (if they send you a number as data you'll get an error from echo for example smile )


$input(Me like stars, You too?)
Re: /socklisten #48089 09/09/03 05:25 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
Code:
alias serv.open {
  socklisten connect 6667
}
alias serv.close {
  sockclose connect
  sockclose client.*
}
alias serv.connect {
  sockopen test $ip 6667
}
alias serv.test {
  sockwrite -tn client.* TEST bkshdg
  sockwrite -tn test test test
}
on *:socklisten:connect:{
  sockaccept client.1
  echo -a client. [ $+ [ $sock(client.1).ip ] ]
  sockrename client.1 client. [ $+ [ $sock(client.1).ip ] ]
}
on *:sockread:client.*:{
  if ($sockerr) { return }
  sockread %client
  tokenize 32 %client
  echo -s $sockname - $1-
}

for the above, i have to /sockwrite to "test", but the sockread event still occurs, but if i /sockwrite to client.* it doesnt work :tongue:


new username: tidy_trax
Re: /socklisten #48090 09/09/03 09:02 PM
Joined: Dec 2002
Posts: 117
R
Rich Offline
Vogon poet
Offline
Vogon poet
R
Joined: Dec 2002
Posts: 117
if you /sockwrite to client.* that means client.* will send data. This will then be received by connect, but since there is no ON SOCKREAD:connect: mIRC discards the data.

Some small things btw:
-you don't need the -t switch for sockwrite if the text you send doesn't start with an ampersand (doesn't do any harm though)
-If you make the name of the accepting socket (client.*) dependant on only the ip of the connection, there could be problems: if someone connects to you twice the ip will be the same, so there will be an error because that socket already exists. To prevent this you could include the remote port in the sockname as well, or use another way of picking a unique name (like using $ticks).


$input(Me like stars, You too?)
Re: /socklisten #48091 09/09/03 09:08 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
Code:
alias serv.start {
  socklisten connect 6667
}
alias serv.close {
  sockclose client.*
  sockclose connect
}
alias serv.connect {
  sockopen client.me $ip 6667
}
alias serv.test {
  sockwrite -tn client.* TEST
}
on *:socklisten:connect:{
  sockaccept client.1
  echo -a client. [ $+ [ $sock(client.1).ip ] ]
  sockrename client.1 client. [ $+ [ $sock(client.1).ip ] ]
}
on *:sockread:client.*:{
  if ($sockerr) { return }
  sockread %client
  tokenize 32 %client
  echo -a $sockname - $1-
}
menu status {
  Open Server: serv.start
  Close Server: serv.close
  Connect: serv.connect
  Test: serv.test
}

this works how i want it :tongue:


new username: tidy_trax