Socket Box

By Zmodem on Sep 28, 2008

Well, what you've got here is a plain old window where you can open a socket connection, basically anywhere, and communicate with it. It accepts your commands and sends it through the socket and waits for responses, which it will send back to you through the window.

This is really just a trial system that will give those of you, who maybe have no idea how to communicate with sockets, a good idea of what you are getting from a server that you attempt to connect to. Enjoy!

Syntax: /socketbox
Opening Connections Example: 255.255.255.0 313
Closing Connections: [QUIT]

alias -l slb { sinfo $chr(160) }
alias -l sbox { return $sock(socketbox) }
alias -l boxnew { sockopen socketbox $1- }
alias -l boxsend { sockwrite -n SocketBox $1- }
alias -l sinfo { if ($1-) echo @SocketBox $1- }
alias -l boxclose { sockclose SocketBox | window -c @SocketBox }
alias -l SboxDo {
  if ($sbox) {
    sinfo -> $1-
    boxsend $1-
    return
  }
  boxnew $1 $2
}
alias socketbox {
  var %s = sinfo
  if ($sbox) {
    var %i = $input(The SocketBox is already open. Do you wish to close the old session and start a new one?,wy,SocketBox Open)
    if (!%i) return
  }
  boxclose
  window -e @SocketBox
  %s SocketBox loaded...
  %s You may open a connection by typing the Hostname/IP Address and port number that you wish to connect to.
  slb
  %s =========================
  %s Example: irc.dal.net 6667
  %s =========================
  slb
}
ON *:INPUT:@SocketBox:{
  if (/* !iswm $1-) {
    if ($1 == [QUIT]) { $iif($sock(SocketBox),sockclose socketbox) | sinfo Connection Closed! | return }
    SboxDo $1-
  }
}
ON *:SOCKOPEN:SocketBox: { sinfo Connection Established: $sock(socketbox).addr $sock(socketbox).port }
ON *:SOCKCLOSE:SocketBox: { sinfo Connection Terminated! }
ON *:SOCKWRITE:SocketBox: { sinfo $1- | boxsend $1- }
ON *:SOCKREAD:SocketBox:{
  if ($sockerr > 0) { sinfo ERROR: $sock(SocketBox).wserr | return }
  var %iData
  :gather
  sockread %iData
  if ($sockbr == 0) return
  if (!%iData) %iData = $chr(160)
  sinfo %iData
  goto gather
}
menu @SocketBox {
  New: { if ($input(Are you sure that you wish to close this session and start a new one?,iy,Confirm New SocketBox)) { boxclose | socketbox } }
  -
  Close:{ if ($input(Are you sure that you wish to close this session?,wy,Confirm Close)) { boxclose } }
}

Comments

Sign in to comment.
Zmodem   -  Oct 23, 2008

It's not primarily a snippet for connecting to IRC at all. This can connect to websites, FTPs, etc. It can download stuff, etc. You just need to know the proper syntax for communicating with the protocol you are attempting to connect to.

 Respond  
TwistedHumor   -  Oct 23, 2008

Suggestion...

Make commands so you can do !sb 5 and make 5 join a room, etc etc.
Make commands so you can do !say and they all will annouce they are here.
Make commands so you can do !p1 and one leave, !p3 and three leave.
Im sure by now you get the idea...
More or less a little challenge...

 Respond  
Zmodem   -  Sep 29, 2008

Okay, one last update. Just small, minor socket issues.

 Respond  
Zmodem   -  Sep 29, 2008

Updated again! A few bug fixes, plus now when you type, it will display it to the screen. I should have done that right off the bat, sorry! Also, changed the syntax. Put your ports after a space:

site.place.dom port

 Respond  
Zmodem   -  Sep 29, 2008

Thanks Noutrious! Updated.

 Respond  
Noutrious   -  Sep 29, 2008
if ($sockerr > 0) { ERROR: $sock(SocketBox).wserr | return }

I think you need sinfo before the ERROR ;)

 Respond  
Paul_1337noob   -  Sep 29, 2008

seems interesting, will have a look when i get home

 Respond  
Zmodem   -  Sep 28, 2008

Well, not sure how useful this is for everyone, just hope you all enjoy it :-)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.