summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Schindelin <[email protected]>2014-03-29 14:53:24 -0500
committerJohannes Schindelin <[email protected]>2014-04-05 18:37:58 -0500
commitc0e012e4d26f2bc38ee5d34c3ee75e94cc799767 (patch)
treebde483617cdf0faa0b9fa4adc946456b9ed85b15
parent7b9fc019de681125df48eb0650d3235aed87d8a5 (diff)
downloadlibtdevnc-c0e012e4d26f2bc38ee5d34c3ee75e94cc799767.tar.gz
libtdevnc-c0e012e4d26f2bc38ee5d34c3ee75e94cc799767.zip
Add an example how to connect to an UltraVNC-style repeater
UltraVNC offers an add-on to connect clients and servers via IDs with a so-called repeater (e.g. to bridge firewalled clients and servers): http://www.uvnc.com/products/uvnc-repeater.html This example demonstrates how to use that feature with a LibVNCServer-based server. Signed-off-by: Johannes Schindelin <[email protected]>
-rw-r--r--.gitignore1
-rw-r--r--examples/Makefile.am2
-rw-r--r--examples/repeater.c62
3 files changed, 64 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 083b816..c675991 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,6 +51,7 @@ examples/fontsel
examples/pnmshow
examples/pnmshow24
examples/regiontest
+examples/repeater
examples/rotate
examples/simple
examples/simple15
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 29d3774..6a7d656 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -23,5 +23,5 @@ noinst_HEADERS=radon.h rotatetemplate.c
noinst_PROGRAMS=example pnmshow regiontest pnmshow24 fontsel \
vncev storepasswd colourmaptest simple simple15 $(MAC) \
$(FILETRANSFER) backchannel $(BLOOPTEST) camera rotate \
- zippy
+ zippy repeater
diff --git a/examples/repeater.c b/examples/repeater.c
new file mode 100644
index 0000000..ae65e25
--- /dev/null
+++ b/examples/repeater.c
@@ -0,0 +1,62 @@
+/* This example shows how to connect to an UltraVNC repeater. */
+
+#include <rfb/rfb.h>
+
+int main(int argc,char** argv)
+{
+ char *repeaterHost;
+ int repeaterPort, sock;
+ char id[250];
+ rfbClientPtr cl;
+
+ int i,j;
+ uint16_t* f;
+
+ /* Parse command-line arguments */
+ if (argc < 3) {
+ fprintf(stderr,
+ "Usage: %s <id> <repeater-host> [<repeater-port>]\n", argv[0]);
+ exit(1);
+ }
+ snprintf(id, sizeof(id) - 1, "ID:%s", argv[1]);
+ repeaterHost = argv[2];
+ repeaterPort = argc < 4 ? 5500 : atoi(argv[3]);
+
+ /* The initialization is identical to simple15.c */
+ rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,5,3,2);
+ if(!server)
+ return 0;
+ server->frameBuffer=(char*)malloc(400*300*2);
+ f=(uint16_t*)server->frameBuffer;
+ for(j=0;j<300;j++)
+ for(i=0;i<400;i++)
+ f[j*400+i]=/* red */ ((j*32/300) << 10) |
+ /* green */ (((j+400-i)*32/700) << 5) |
+ /* blue */ ((i*32/400));
+
+ /* Now for the repeater-specific part: */
+ server->port = -1; /* do not listen on any port */
+ server->ipv6port = -1; /* do not listen on any port */
+
+ sock = rfbConnectToTcpAddr(repeaterHost, repeaterPort);
+ if (sock < 0) {
+ perror("connect to repeater");
+ return 1;
+ }
+ if (write(sock, id, sizeof(id)) != sizeof(id)) {
+ perror("writing id");
+ return 1;
+ }
+ cl = rfbNewClient(server, sock);
+ if (!cl) {
+ perror("new client");
+ return 1;
+ }
+ cl->reverseConnection = 0;
+
+ /* Run the server */
+ rfbInitServer(server);
+ rfbRunEventLoop(server,-1,FALSE);
+
+ return 0;
+}