Android™ Requires Chilkat v11.6.0+
Android™
Configure MCP Connection Settings
See more MCP Client Examples
Demonstrates Mcp.SetConnectionSettings, which copies connection settings -- such as an HTTP proxy, SOCKS proxy, bind IP address, and TLS options -- from a Socket and applies them before connecting.
Background. This is optional; if not used, a direct connection is made. It is useful when the MCP server must be reached through a proxy or with specific TLS settings.
Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
CkMcp mcp = new CkMcp();
// Configure connection settings on a Socket -- such as an HTTP proxy, SOCKS proxy, bind IP address,
// or TLS options -- and apply them to the MCP client before connecting. This is optional; if not
// used, a direct connection is made.
CkSocket sock = new CkSocket();
sock.put_HttpProxyHostname("proxy.example.com");
sock.put_HttpProxyPort(8080);
success = mcp.SetConnectionSettings(sock);
if (success == false) {
Log.i(TAG, mcp.lastErrorText());
return;
}
success = mcp.Connect("https://learn.microsoft.com/api/mcp");
if (success == false) {
Log.i(TAG, mcp.lastErrorText());
return;
}
Log.i(TAG, "Connected using the configured connection settings.");
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}