Search:

Search all manuals
Search this manual
Manual
Membase Client Library: Java
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
1 Membase Client Library: Java — Getting Started
Chapter Sections
Chapters

1.2. Connecting using Hostname and Port

The constructor for MemcachedClient supports three different formats:

To make a standard connection to your Membase node using a standard hostname and port combination you can use the InetSocketAddress class when creating the MemcachedClient object. This allows you to explicitly specify the hostname and port numbers. For example, to connect to the host servera on port 11211:

MemcachedClient c = new MemcachedClient(
    new InetSocketAddress("servera", 11211));

You can also use a hostname:port string by using the AddrUtil utility class to parse strings into hostname and port combinations. The AddrUtil.getAddresses() method parses the string and returns a List of InetSocketAddress objects . The sample below is the equivalent code to the InetSocketAddress method used above:

MemcachedClient c = new MemcachedClient(
    AddrUtil.getAddresses("servera:11211")););

The AddrUtil utility class is also the easiest method for specifying multiple hostname/port combinations, by separating each hostname:port combination with a space:

MemcachedClient c = new MemcachedClient(
    AddrUtil.getAddresses("servera:11211 serverb:11211")););

The MemcachedClient constructors return the IOException exception if a valid connection is unable to be made.