Commit 097d5d60 authored by Benjamin Krämer's avatar Benjamin Krämer

Added Receiver example

parent 02e5f69e
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="jar" name="gs-netstream">
<property name="bindir" value="bin/"/>
<property name="srcdir" value="src/"/>
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.5"/>
<property name="source" value="1.5"/>
<path id="this.classpath">
<pathelement location="${bindir}"/>
</path>
<target name="init">
<mkdir dir="${bindir}"/>
<copy todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="${bindir}"/>
<delete file="${ant.project.name}.jar"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build" name="jar">
<jar jarfile="${ant.project.name}.jar" basedir="${bindir}"/>
</target>
<target depends="init" name="build">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="${bindir}" source="${source}" target="${target}">
<src path="${srcdir}"/>
<classpath refid="this.classpath"/>
</javac>
</target>
</project>
import java.io.IOException;
import java.net.UnknownHostException;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.MultiGraph;
import org.graphstream.stream.netstream.NetStreamReceiver;
import org.graphstream.stream.thread.ThreadProxyPipe;
/**
* A simple example of use of the NetStream receiver.
*/
public class ReceiverExample {
public static void main(String[] args) throws UnknownHostException, IOException, InterruptedException {
// ----- On the receiver side -----
//
// - a graph that will display the received events
Graph g = new MultiGraph("G");
g.display();
// - the receiver that waits for events
NetStreamReceiver net = new NetStreamReceiver(2001);
net.setDebugOn(true);
// - received events end up in the "default" pipe
ThreadProxyPipe pipe = net.getDefaultStream();
// - plug the pipe to the sink of the graph
pipe.addSink(g);
// -The receiver pro-actively checks for events on the ThreadProxyPipe
while (true) {
pipe.pump();
Thread.sleep(100);
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment