Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Bind channel to socket

Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
08-26-2006 15:45
I have suggested this before, but let's do it again... with code!

LSL should provide a mechanism to bind a local port (for example 127.0.0.1:1700 through 127.0.0.1:1800) to a chat channel, so that a program on the local machine could write strings to (say) 127.0.0.1:1700 and have them come out on whatever channel the script specified, as if you had said them, and have messages on the channel be written back to the program over the port.

For example:

CODE

state_entry()
{
llBindSocket(123456,2); // Bind channel 123456 to socket 2 (port 1702).
}

Then you could use this POSIX C program to write "Hello Second Life" on channel 123456:
CODE

main()
{
char *message="Hello Second Life\n";
integer sock = socket(AF_INET,SOCK_STREAM,0);
struct sockaddr_in addr;
fill_sockaddr_in(&addr,inet_addr("127.0.0.1"),htons(1702));
if(sock < 0 || connect(sock,&addr,sizeof addr) < 0)
{
perror("connect socket");
exit(1);
}
write(sock,message,strlen(message));
close(sock);
exit(0);
}
This program would work on Mac OS X or Linux directly, and on Windows with the aid of something like Cygwin, U/Win, or Microsoft's own Interix. The comparable Windows native code ouldn't be much more complicated, and you could even test it with
CODE

C:> TELNET LOCALHOST 1702
Hello Second Life!
^]telnet> quit

C:>


By bindng to localhost (127.0.0.1) you could guarantee that no-one on the internet could sneak in to the port, it would only be able to get connections from programs running on the same computer. For additional security, you could have a preference in the client (the SL application on your PC) to allow it ALWAYS, NEVER, or ASK FOR PERMISSION.
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
08-27-2006 10:11
What do you do when the avatar leaves the sim? What do you do when there's no avatar around to bind to? Why not just use XML-RPC?
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
08-27-2006 19:01
What do you do when the avatar leaves the sim?

If the avatar leaves the sim the script goes with him.

What do you do when there's no avatar around to bind to?

If the avatar's not there how does the script run?

Note that the call doesn't include anything to designate what agent is being communicated through. It doesn't really make a lot of sense, except in an attachment or vehicle, just like, for example, llStartAnimation() and llTakeControls(). Applications for some few of these kinds of calls in objects like dance balls is the exception, rather than the rule.

This would be a way for you to run code on your desktop that's "virtually" attached to your avatar, without having to use hacks like libsl. It's got nothing to do with anything you'd use XMLRPC for. Using XMLRPC to control a vehicle would be rather difficult... using a scheme like this would be easy.