Author Topic: Call a function from another program [Solved]  (Read 2728 times)

Is there any way I can have another program call a function in Blockland?

IE:
>programB: reached function 'setAv(args args args);'
 -call functions required to change avatar in any open Blockland windows
« Last Edit: January 19, 2013, 08:24:37 PM by ThinkInvisible »



And I would use these to do this how?
Send data through a specific port via TCP objects in Blockland and have your external program listening on that same port waiting to receive data.

if you wanted to know how to actually call the function, you'd use call. (eg call('echo', "hey guys here's a message for you lol");, not sure if the function needs to be in tags, but i'd assume so)

though i figure you probably already knew that

As stated above, you need to create a 'connection' between Blockland and the external program. TCP objects are the best way to go. Create a simple server on the Blockland side. In the servers ::onLine function have code for figuring out which function to call etc. On the external program's part, you need to create a client with some type of TCP socket. Once you connect, the data that you send calls the ::onLine function on Blocklands part. This is pretty easy for experienced users but would be a nice challenge for new users.


function InitConnection(%server,%port) //Creates a tcp object
{
   if(isObject(TCPObjecty))
   TCPObjecty.delete();
   new TCPObject(TCPObjecty)
   {
      site = %server;
      port = %Port;
      
      connected = 0;
   };
}
function TCPObjecty:onLine(%this,%line) //Called when client gets sent stuff
{
}

function TCPObjecty::sendLine(%this,%line) //Sends a line
{
   %this.send(%line);
}
function TCPObjecty::onConnected(%this) //called when connected
{
    %this.connected = 1;
}

TCPObjecty.connect(%server@":"@%port); //Attempts to connect
TCPObjecty.disconnect();

^^ Un-needed because:
this excellent post  by Trinick
« Last Edit: January 19, 2013, 03:03:05 AM by MARBLE MAN »

I don't know any of the code I need though. The external program is in C#.

And both of these programs are on the same computer, which would probably create a faster method that doesn't require routing and stuff.

I don't know any of the code I need though. The external program is in C#.

And both of these programs are on the same computer, which would probably create a faster method that doesn't require routing and stuff.
Even with both programs being on the same machine, TCP are going to be the fastest way to transfer data between the two. If you really don't want to go through the process of learning TCPs then you could do some weird workaround like writing to a text file and having both programs read from that.

EDIT:

function InitConnection(%server,%port) //Creates a tcp object
{
   if(isObject(TCPObjecty))
   TCPObjecty.delete();
   new TCPObject(TCPObjecty)
   {
      site = %server;
      port = %Port;
      
      connected = 0;
   };
}
function TCPObjecty:onLine(%this,%line) //Called when client gets sent stuff
{
}

function TCPObjecty::sendLine(%this,%line) //Sends a line
{
   %this.send(%line);
}
function TCPObjecty::onConnected(%this) //called when connected
{
    %this.connected = 1;
}

TCPObjecty.connect(%server@":"@%port); //Attempts to connect
TCPObjecty.disconnect();

^^ Un-needed because:
this excellent post  by Trinick
Your code is broken in a few ways. Second to last line you're calling a local variable outside of a function. One of the functions needs another colon.
« Last Edit: January 19, 2013, 08:34:59 AM by Daenth »

Well, I managed to get a simple client/server system working entirely in C#.
Is there any way to use TCPobjects that doesn't require a port forwarded?

(I don't like ports because I opened one for Minecraft once. My internet started lagging to hell until I unforwarded the port.)


Whoa whoa wait whoa whoa.
C# has a 'TCPlistener' and 'TCPclient'. How is this different from just one 'TCPobject'?

If it's over local connections, you shouldn't have to have your ports forwarded. Your firewall must allow Blockland through those specific ports however.

IIRC, TCPObjects and TCPClients are the same thing. TCPListeners do exactly what their name implies, they listen on a port but don't send any data.

If it's over local connections, you shouldn't have to have your ports forwarded. Your firewall must allow Blockland through those specific ports however.

IIRC, TCPObjects and TCPClients are the same thing. TCPListeners do exactly what their name implies, they listen on a port but don't send any data.
But TCPlisteners in C# seem to be able to send data. The example I found and used to help with the script involves the listener (being the server) sending a response to the client after it receives data.

Also should I have Blockland as the client or the server?
« Last Edit: January 19, 2013, 09:22:06 AM by ThinkInvisible »

But TCPlisteners in C# seem to be able to send data. The example I found and used to help with the script involves the listener (being the server) sending a response to the client after it receives data.

Also should I have Blockland as the client or the server?
I have no idea then. I haven't dabbled too much with C# and TCP so I'll let someone who actually knows what they're talking about answer that.

It depends on what the external program will do, but realistically it shouldn't matter with this simple of a connection.

The external command is going to be sending Blockland a series of strings and a Blockland script will decide what to do with them. If possible, I would like it to alternate between the program sending Blockland information and Blockland sending the program feedback ('yes, I have this string, and I did this with it')

Ohwaitgod. C# needs to convert the data to bytes to transmit it. How do I decode this in Blockland?
(The method used in C# is System.Text.ASCIIEncoding.Get Bytes(string s))
« Last Edit: January 19, 2013, 09:49:47 AM by ThinkInvisible »

The external command is going to be sending Blockland a series of strings and a Blockland script will decide what to do with them. If possible, I would like it to alternate between the program sending Blockland information and Blockland sending the program feedback ('yes, I have this string, and I did this with it')
Then technically there is no server (it'd be considered a peer-to-peer connection) so it doesn't matter.

EDIT:
Ohwaitgod. C# needs to convert the data to bytes to transmit it. How do I decode this in Blockland?
(The method used in C# is System.Text.ASCIIEncoding.Get Bytes(string s))
You'll have to ask someone else as I have no idea about that.
« Last Edit: January 19, 2013, 09:55:04 AM by Daenth »