Click here to Skip to main content
16,016,882 members
Articles / Programming Languages / C#

LiteCode - Remotely call methods over the network

Rate me:
Please Sign up or sign in to vote.
4.77/5 (9 votes)
21 Nov 2012CPOL3 min read 13.6K   39   4
Remotely invoke methods over the internet super easy

Introduction 

You are having enough of crackers, reverse engineers? With LiteCode you can host your code remotely at a server where no cracker can touch it. Your source code will become even more private than ever with more protection and no source code obfuscation required.

Features  

  • Using the SSP protocol for having a scalable server and having the traffic Encrypted/Compressed http://ssp.codeplex.com/
  • Host your code where no cracker can ever touch it to get your software cracked
  • You don't need a lot of knowledge about networking how to send packets and such that is all being done in the background
  • Shared Classes is a new technique to remotely call methods in the client or server to make it easy for the end-user to understand what is going on in the code
  • Shared classes
  • System classes (under construction); currently there is Graphics, Cursor
  • Delegates (callback methods), example is shown below
  • Supports properties, overloaded methods
  • Call methods over the UDP protocol using the attribute UdpMethod
  • The NoWait attribute will not wait till the other side completed the method and does not wait till the packet is being sent
  • The PacketQueue attribute will use the PacketQueue from SSP, could increase performance 

What happens in the background 

A dummy class is being created in the background used to inject code but that's not important. Code is being injected in the dummy class so that you're able to call method's at the server/client side. The code from the server/client side will never leave or is sent to the server/client side. The most important part here is that the server contains all the sensitive information and the client does not. The injected code in the dummy class will only say to the server/client, call this method for me and if you can return the result. This way both sides can never inject each other with possible malicious code.

If people are interested in the code injection here you go:

C#
internal class DynamicClassCreator
{
    static object Locky = new object();
    internal static SortedList<string, Type>

Using the code

Server sided:

C#
namespace Server
{
    class Program
    {
        static void Main(string[] args)
        {
            //start the server at port 1234 using TCP and UDP
            LiteServer server = new LiteServer(1234, "0.0.0.0", 
                                      NetworkProtocol.TCP | NetworkProtocol.UDP);
            server.onClientConnect += (Client client) =>
            {
                ITest test = client.GetSharedClass<ITest>("test");
                //get the class from the client, client shared a class called "test"

                test.TestDelegate(":O", new TestDel((string val) =>
                //very simple just call the method and give as argument a delegate
                {
                    //whenever this delegate is called, the client side invoked the delegate
                    Console.WriteLine("Message from client: " + val);
                }));
            };
            Console.WriteLine("Providing remote code at port 1234");
            Process.GetCurrentProcess().WaitForExit();
        }
    }
}

Client side:

C#
namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
        //connect to the server at ip 127.0.0.1 at port 1234
            LiteClient client = new LiteClient("127.0.0.1", 1234, 
              SecureSocketProtocol.NetworkProtocol.TCP | 
              SecureSocketProtocol.NetworkProtocol.UDP, null, null,
            (LiteClient c) => 
            {
                //this delegate is being called before we
                //connected so the server can grab this shared class
                c.ShareClass("test", typeof(Dummy_Testy));
                //share a class with the name "test"
            }, (LiteClient c) =>
            {
                Process.GetCurrentProcess().WaitForExit();
            });
        }
    }

    public class Dummy_Testy : ITest
    {
        [RemoteExecution]
        public string TestMe()
        {
            return "This is a message from the client";
        }

        [RemoteExecution]
        public void TestDelegate(string SomeValue, 
           [UdpMethod] [UncheckedRemoteExecution] TestDel CallMe)
        {
            while(true)
                CallMe("some string from Client Side :)");
        }
    }
}

public delegate void TestDel(string ar);
public interface ITest
{
  string TestMe();
  void TestDelegate(string test, TestDel CallMe);
}

This is just a very basic server/client as you can see when the client is connected to the server. The server is now able to call two methods, TestMe and TestDelegate. You can see when the server calls TestMe(); it will return "This is a message from the client". And if the server calls TestDelegate and gives a delegate with it the client will be able to call. The method the server gave in that example will just keep calling the delegate in a while(true).

Points of interest

The interest I had to code this library was to make networking super easy for anyone for new and advanced users. Even myself if I had to make a program used in networking I would use my LiteCode library. Just because it's too easy to setup a secure connection and calling methods and communicating synchronized with the client/server. I also was becoming lazy of using the... SendPacket(...) and after that Receive(...) for an answer. What if the program was doing like 10 things at the same time, you might receive a different packet than you expected? In LiteCode it's so easy you just call the method and give it a delegate so it can return whatever value.

Links

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
QuestionWhat's wrong with WCF for calling the server to do something? Pin
Maxim Novak26-Nov-12 22:30
Maxim Novak26-Nov-12 22:30 
What's wrong with WCF for calling the server to do something?
Questiongood work buddy :D Pin
salmoneus21-Nov-12 8:16
salmoneus21-Nov-12 8:16 
GeneralMy vote of 5 Pin
soulprovidergr21-Nov-12 5:04
soulprovidergr21-Nov-12 5:04 
GeneralGood Pin
HoshiKata21-Nov-12 3:15
HoshiKata21-Nov-12 3:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.