remote kafka


The official demo, kafka.apache.org/quickstart, shows how to run kafka with everything on localhost.
Here are the steps to run kafka server remotely.
tech.riowing.net is the server, which runs kafka zookeeper and brokers on ubuntu in aws
WSL, a windows desktop, runs kafka producer and consumer on WSL ubuntu on local windows

On both AWS and WSL:
download kafka tar ball and extract:
http://apache.claz.org/kafka/2.3.0/kafka_2.12-2.3.0.tgz 57M
extract to: /mnt/ebs/rio/opensrc/kafka/kafka_2.12-2.3.0
install java. I got OpenJDK 64-Bit Server VM build 11

On AWS, server side:
export KAFKA_OPTS=”-Djava.net.preferIPv4Stack=True”
otherwise it’s IPV6
edit server.properties so that:
advertised.listeners=PLAINTEXT://tech.riowing.net:9092
otherwise client report error: Connection to node 0 (localhost/127.0.0.1:9092)
start zookeepter:
bin/zookeeper-server-start.sh config/zookeeper.properties
start server:
bin/kafka-server-start.sh config/server.properties

On WSL, client side:
Send message:
bin/kafka-console-producer.sh –broker-list tech.riowing.net:9092 –topic test
type some text, ctrlD to exit
Check message received:
bin/kafka-console-consumer.sh –bootstrap-server tech.riowing.net:9092 –topic test –from-beginning
ctrlC to exit

Roku ECP


Roku TV can be controlled by ECP External Control Protocol.
For example, by running a curl command, a channel can be started or switch to playing another video.
Here are two sample commands:
1. start channel and playing the gym video:
Cmd: curl -d ” ‘http://10.15.26.39:8060/launch/dev?contentID=Gym&mediaType=movie’
“contentID=Gym” is to tell channel which piece of video to play once started.
2. while channel is already running, switch to another video, which is dance party.
curl -d ” ‘http://10.15.26.39:8060/input?contentID=Party&mediaType=movie’

How it is done:
Firmware interpret “launch/dev” as launching the channel whose channel ID is “dev”
Firmware passes {contentId: Gym, type: mp4} to channel entry function Main(args) so that channel knows what to do, e.g. what video to play.
Firmware interpret “input?contentID=Party” as sending {contentID: Party} to the current running channel so that channel, through roInput, knows what to do, e.g. in this case, switching to video called Party.

EcpThe channel source code: http://riowing.net/p/deepLinkDstPost.zip
The screen recording: http://riowing.net/p/Ecp.mp4, which show the TV on left, and my linux box on the right.

Range Based For


Range Based For is new in c++11

void RangeBasedFor()
{
	nullptr_t pN = nullptr;
	void *pV = reinterpret_cast(1);
	int *pI = reinterpret_cast(2);
	void *arr[] = { pV, pN, pI };
	std::cout << "enumerating void *arr[] with Range Based For syntax" << std::endl;
	//other options: auto i, auto&& i
	for (const auto &i : arr) //auto or int, arr can be replaced directly by {2, 3}
		std::cout << i << std::endl;

	std::vector arr2 = { 3, 4 };
	std::cout << "enumerating vector with Range Based For syntax" << std::endl;
	for (const auto &i : arr2) //works for both int[] and vector
		std::cout << i << std::endl;
	std::cout << "enumerating vector with regular for loop" << std::endl;
	for(std::vector::iterator i = arr2.begin(); i != arr2.end(); ++i) //only for vector
		std::cout << *i << std::endl;
}

 

Output:
enumerating void *arr[] with Range Based For syntax
0000000000000001
0000000000000000
0000000000000002
enumerating vector with Range Based For syntax
3
4
enumerating vector with regular for loop
3
4

 

download with pseudo device


These commands were tested in Ubuntu, including WSL

exec 5<> /dev/tcp/riowing.net/80
echo -e “GET /riosite/p/exec.txt HTTP/1.0\n” >&5
cat <&5
output:
HTTP/1.1 200 OK
# more info such as server version, date, content type…
FromRioWingNet # this is the content of exec.txt

exec.txt has been downloaded at this point

Here is more investigation:
$ ls /dev/tcp #output: No such file or directory
$ ls -l /dev/fd/5
lrwx—— 1 rio rio 0 Nov 3 17:56 /proc/self/fd/5 -> ‘socket:[43]’
#/dev/fd is a symbolic link to /proc/self/fd
$ echo $$ #output 9
$ ls -l /proc/9/fd/5
lrwx—— 1 rio rio 0 Nov 3 18:05 /proc/9/fd/5 -> ‘socket:[43]’
#fd means file descriptor

Bottom line: the 5 in “exec 5” is the 5 in /proc/9/fd/5