Fork me on GitHub

Network Your Software

Trusted by Industry Leaders

Ice

A Comprehensive RPC Framework

Flexible

Make synchronous and asynchronous invocations using TCP, UDP, SSL/TLS, and WebSockets. Bidirectional connections allow a server to reuse a connection established by a client to make callbacks.

Secure

Ice offers powerful and easy to use security features. The IceSSL plug-in uses your operating system's SSL/TLS stack to encrypt your data and authenticate your connections.

Fast

Ice uses a compact, efficient binary protocol to minimize CPU and bandwidth consumption.

Everywhere

Develop in C++, C#, Java, JavaScript, Objective-C, PHP, Python, and Ruby. Deploy on Linux, macOS, Windows, Android, and iOS.

An Introduction to

Ice

Slice - Ice's Interface Definition Language

// Printer.ice
module Demo
{
    interface Printer
    {
        // A client can invoke this operation on a server.
        // In this example we print the string s
        void printString(string s);
    }
}

Compile Slice to C++, C#, Java, ...

# compile Slice               # generated files
slice2cpp  Printer.ice        # Printer.h, Printer.cpp
slice2cs   Printer.ice        # Printer.cs
slice2java Printer.ice        # Demo/Printer.java, Demo/...
slice2js   Printer.ice        # Printer.js
slice2objc Printer.ice        # Printer.h, Printer.m
slice2php  Printer.ice        # Printer.php
slice2py   Printer.ice        # Printer.py
slice2rb   Printer.ice        # Printer.rb

Implement Printer Interface in C++

class PrinterI : public Demo::Printer
{
public:
    virtual void printString(string s, const Ice::Current&) override
    {
        cout << s << endl;
    }
};

Write your server in C++

// Initialize Ice communicator - used for interacting with the Ice runtime
Ice::CommunicatorHolder ich(argc, argv);

// Instantiate a new PrinterI servant - the implementation of your Printer
auto servant = make_shared<PrinterI>();

// Create object adapter - a container for your servants. Listens on port 10000
auto adapter = ich->createObjectAdapterWithEndpoints("SimplePrinterAdapter", "tcp -p 10000");

// Add the servant object to the object adapter with identity "SimplePrinter"
adapter->add(servant, ich->stringToIdentity("SimplePrinter"));

// Activate object adapter - accept incoming requests and dispatch them to servants
adapter->activate();

// Wait for communicator to shut down
ich->waitForShutdown();

Implement Printer Interface in C#

public class PrinterI : Demo.PrinterDisp_
{
    public override void printString(string s, Ice.Current current)
    {
        Console.WriteLine(s);
    }
}

Write your server in C#

// Initialize Ice communicator - used for interacting with the Ice runtime
using(var communicator = Ice.Util.initialize(ref args))
{
    // Instantiate a new PrinterI servant - the implementation of your Printer
    var servant = new PrinterI();

    // Create object adapter - a container for your servants. Listens on port 10000
    var adapter = communicator.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "tcp -p 10000");

    // Add the servant object to the object adapter with identity "SimplePrinter"
    adapter.add(servant, communicator.stringToIdentity("SimplePrinter"));

    // Activate object adapter - accept incoming requests and dispatch them to servants
    adapter.activate();

    // Wait for communicator to shut down
    communicator.waitForShutdown();
}

Implement Printer Interface in Java

public class PrinterI implements Demo.Printer
{
    @Override
    public void printString(String s, Ice.Current current)
    {
        System.out.println(s);
    }
}

Write your server in Java

// Initialize Ice communicator - used for interacting with the Ice runtime
try(Ice.Communicator communicator = Ice.Util.initialize(args))
{
    // Instantiate a new PrinterI servant - the implementation of your Printer
    Ice.Object servant = new PrinterI();

    // Create object adapter - a container for your servants. Listens on port 10000
    Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "tcp -p 10000");

    // Add the servant object to the object adapter with identity "SimplePrinter"
    adapter.add(servant, communicator.stringToIdentity("SimplePrinter"));

    // Activate object adapter - accept incoming requests and dispatch them to servants
    adapter.activate();

    // Wait for communicator to shut down
    communicator.waitForShutdown();
}

Implement Printer Interface in Objective-C

@interface PrinterI : DemoPrinter<DemoPrinter>
@end

@implementation PrinterI
-(void) printString:(NSMutableString*)s current:(ICECurrent*)current
{
    printf("%s\n", [s UTF8String]);
}
@end

Write your server in Objective-C

// Initialize Ice communicator - used for interacting with the Ice runtime
id<ICECommunicator> communicator = communicator = [ICEUtil createCommunicator:&argc argv:argv];

// Instantiate a new PrinterI servant - the implementation of your Printer
ICEObject *servant = [PrinterI printer];

// Create object adapter - a container for your servants. Listens on port 10000
id<ICEObjectAdapter> adapter = [communicator createObjectAdapterWithEndpoints: @"SimplePrinterAdapter"
                                                  endpoints: @"tcp -p 10000"];

// Add the servant object to the object adapter with identity "SimplePrinter"
[adapter add:servant identity:[communicator stringToIdentity:@"SimplePrinter"]];

// Activate object adapter - accept incoming requests and dispatch them to servants
[adapter activate];

// Wait for communicator to shut down
[communicator waitForShutdown];

// Destroy Ice communicator
[communicator destroy];

Implement Printer Interface in Python

class PrinterI(Demo.Printer):
    def printString(self, s):
        print(s)

Write your server in Python

# Initialize Ice communicator - used for interacting with the Ice runtime
with Ice.initialize(sys.argv) as communicator:
    # Instantiate a new PrinterI servant - the implementation of your Printer
    servant = PrinterI()

    # Create object adapter - a container for your servants. Listens on port 10000
    adapter = communicator.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "tcp -p 10000")

    # Add the servant object to the object adapter with identity "SimplePrinter"
    adapter.add(servant, communicator.stringToIdentity("SimplePrinter"))

    # Activate object adapter - accept incoming requests and dispatch them to servants
    adapter.activate()

    # Wait for communicator to shut down
    communicator.waitForShutdown();

Say Hello using Ice for C++

// Initialize Ice communicator - used for interacting with the Ice runtime
Ice::CommunicatorHolder ich(argc, argv);

// Create a proxy to the remote Printer object
auto obj = ich->stringToProxy("SimplePrinter:tcp -h serverhost.serverdomain -p 10000");

// Downcast obj to Printer proxy
auto printer = Ice::checkedCast<PrinterPrx>(obj);

// Invoke "printString" operation on remote Printer object
printer->printString("Hello World!");

Say Hello using Ice for C#

// Initialize Ice communicator - used for interacting with the Ice runtime
using(var communicator = Ice.Util.initialize(ref args))
{
    // Create a proxy to the remote Printer object
    Ice.ObjectPrx obj = communicator.stringToProxy("SimplePrinter:tcp -h serverhost.serverdomain -p 10000");

    // Downcast obj to Printer proxy
    var printer = Demo.PrinterPrxHelper.checkedCast(obj);

    // Invoke "printString" operation on remote Printer object
    printer.printString("Hello World!");
}

Say Hello using Ice for Java

// Initialize Ice communicator - used for interacting with the Ice runtime
try(Ice.Communicator communicator = Ice.Util.initialize(args))
{
    // Create a proxy to the remote Printer object
    Ice.ObjectPrx obj = communicator.stringToProxy("SimplePrinter:tcp -h serverhost.serverdomain -p 10000");

    // Downcast obj to Printer proxy
    Demo.PrinterPrx printer = Demo.PrinterPrxHelper.checkedCast(obj);

    // Invoke "printString" operation on remote Printer object
    printer.printString("Hello World!");
}

Say Hello using Ice for Objective-C

// Initialize Ice communicator - used for interacting with the Ice runtime
id<ICECommunicator> communicator = [ICEUtil createCommunicator:&argc argv:argv];

// Create a proxy to the remote Printer object
id<ICEObjectPrx> obj = [communicator stringToProxy:@"SimplePrinter:tcp -h serverhost.serverdomain -p 10000"];

// Downcast obj to Printer proxy
id<DemoPrinterPrx> printer = [DemoPrinterPrx checkedCast:obj];

// Invoke "printString" operation on remote Printer object
[printer printString:@"Hello World!"];

// Destroy Ice communicator
[communicator destroy];

Say Hello using Ice for Python

# Initialize Ice communicator - used for interacting with the Ice runtime
with Ice.initialize(sys.argv) as communicator:
    # Create a proxy to the remote Printer object
    obj = communicator.stringToProxy("SimplePrinter:tcp -h serverhost.serverdomain -p 10000")

    # Downcast obj to Printer proxy
    printer = Demo.PrinterPrx.checkedCast(obj)

    # Invoke "printString" operation on remote Printer object
    printer.printString("Hello World!")

Say Hello using Ice for JavaScript

// Initialize Ice communicator - used for interacting with the Ice runtime
let communicator = Ice.initialize();

// Create a proxy to the remote Printer object
let obj = communicator.stringToProxy("SimplePrinter:tcp -h serverhost.serverdomain -p 10000");

// Downcast obj to Printer proxy
Demo.PrinterPrx.checkedCast(obj).then(printer =>
{
    // Invoke "printString" operation on remote Printer object
    return printer.printString("Hello World!");
})
.finally(() =>
{
    // Destroy Ice communicator
    communicator.destroy();
});

Say Hello using Ice for PHP

// Initialize Ice communicator - used for interacting with the Ice runtime
$communicator = Ice\initialize();

// Create a proxy to the remote Printer object
$obj = $communicator->stringToProxy("SimplePrinter:tcp -h serverhost.serverdomain -p 10000");

// Downcast obj to Printer proxy
$printer = Demo\PrinterPrxHelper::checkedCast($obj);

// Invoke "printString" operation on remote Printer object
$printer->printString("Hello World!");

// Destroy Ice communicator
$communicator->destroy();

Say Hello using Ice for Ruby

# Initialize Ice communicator - used for interacting with the Ice runtime
communicator = Ice::initialize(ARGV)

# Create a proxy to the remote Printer object
obj = communicator.stringToProxy("SimplePrinter:tcp -h serverhost.serverdomain -p 10000")

# Downcast obj to Printer proxy
printer = Demo::PrinterPrx::checkedCast(obj)

# Invoke "printString" operation on remote Printer object
printer.printString("Hello World!")

# Destroy Ice communicator
communicator.destroy();

Language Mappings

Ice for C++Ice for C#Ice for JavaIce for JavaScriptIce for Objective-CIce for PHPIce for PythonIce for Ruby

Ice Services

Ice is more than a RPC framework. It also provides a number of complementary services for your networked applications.

IceGrid

Deployment and Monitoring

Glacier2

Firewall Traversal

IceStorm

Event Publish/Subscribe

Get Started with Ice

Whether you're working on an enterprise application or hobbyist project, Ice makes it easy to network your software.

Download Ice  Documentation

Need help? Join our forums.