Package lcm.lcm

# Class LCM

java.lang.Object
lcm.lcm.LCM

public class LCM extends Object
Lightweight Communications and Marshalling Java implementation

## Constructor Summary

Constructors
Constructor
Description
`LCM(String... urls)`
Create a new LCM object, connecting to one or more URLs.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Call this function to release all resources used by the LCM instance.
`static String`
`getDefaultURL()`
`int`
`getNumSubscriptions()`
Return the number of subscriptions.
`static LCM`
`getSingleton()`
Retrieve a default instance of LCM using either the environment variable LCM_DEFAULT_URL or the default.
`static void`
`main(String[] args)`
Minimalist test code.
`void`
`publish(String channel, byte[] data, int offset, int length)`
Publish raw data on a channel, bypassing the LCM type specification.
`void`
`publish(String channel, String s)`
Publish a string on a channel.
`void`
`publish(String channel, LCMEncodable e)`
Publish an LCM-defined type on a channel.
`void`
`receiveMessage(String channel, byte[] data, int offset, int length)`
Not for use by end users.
`void`
`subscribe(String regex, LCMSubscriber sub)`
Subscribe to all channels whose name matches the regular expression.
`void`
`subscribeAll(LCMSubscriber sub)`
A convenience function that subscribes to all LCM channels.
`void`
`unsubscribe(String regex, LCMSubscriber sub)`
Remove this particular regex/subscriber pair (UNTESTED AND API MAY CHANGE).

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### LCM

public LCM(String... urls) throws IOException
Create a new LCM object, connecting to one or more URLs. If no URL is specified, the environment variable LCM_DEFAULT_URL is used. If that environment variable is not defined, then the default URL is used.

Throws:
  `IOException`

## Method Details

### getDefaultURL

public static String getDefaultURL()

Returns:
  The value of the LCM_DEFAULT_URL environment variable if set or "udpm://239.255.76.67:7667".

### getSingleton

public static LCM getSingleton()
Retrieve a default instance of LCM using either the environment variable LCM_DEFAULT_URL or the default. If an exception occurs, System.exit(-1) is called.

### getNumSubscriptions

public int getNumSubscriptions()
Return the number of subscriptions.

### publish

public void publish(String channel, String s) throws IOException
Publish a string on a channel. This method does not use the LCM type definitions and thus is not type safe. This method is primarily provided for testing purposes and may be removed in the future.

Throws:
  `IOException`

### publish

public void publish(String channel, LCMEncodable e)
Publish an LCM-defined type on a channel. If more than one URL was specified, the message will be sent on each.

### publish

public void publish(String channel, byte[] data, int offset, int length) throws IOException
Publish raw data on a channel, bypassing the LCM type specification. If more than one URL was specified when the LCM object was created, the message will be sent on each.

Throws:
  `IOException`

### subscribe

public void subscribe(String regex, LCMSubscriber sub)
Subscribe to all channels whose name matches the regular expression. Note that to subscribe to all channels, you must specify ".*", not "*".

### unsubscribe

public void unsubscribe(String regex, LCMSubscriber sub)
Remove this particular regex/subscriber pair (UNTESTED AND API MAY CHANGE). If regex is null, all subscriptions for 'sub' are cancelled. If subscriber is null, any previous subscriptions matching the regular expression will be cancelled. If both 'sub' and 'regex' are null, all subscriptions will be cancelled.

### receiveMessage

public void receiveMessage(String channel, byte[] data, int offset, int length)
Not for use by end users. Provider back ends call this method when they receive a message. The subscribers that match the channel name are synchronously notified.

### subscribeAll

public void subscribeAll(LCMSubscriber sub)
A convenience function that subscribes to all LCM channels.

### close

public void close()
Call this function to release all resources used by the LCM instance. After calling this function, the LCM instance should consume no resources, and cannot be used to receive or transmit messages.

### main

public static void main(String[] args)
Minimalist test code.