summaryrefslogtreecommitdiffstats
path: root/client_examples/backchannel.c
diff options
context:
space:
mode:
authordscho <dscho>2005-10-06 19:26:41 +0000
committerdscho <dscho>2005-10-06 19:26:41 +0000
commit194a76df115db3b6fe62adbccfe4181ed46d2c52 (patch)
tree1b7e853cbd4c4482173d3b2f675580169dfd56d6 /client_examples/backchannel.c
parent11fc700c5db6afc6978211f5735707848b94ae8e (diff)
downloadlibtdevnc-194a76df115db3b6fe62adbccfe4181ed46d2c52.tar.gz
libtdevnc-194a76df115db3b6fe62adbccfe4181ed46d2c52.zip
add an extension mechanism for LibVNCClient, modify the client data handling
so that more than one data structure can be attached, and add an example to speak the client part of the back channel.
Diffstat (limited to 'client_examples/backchannel.c')
-rw-r--r--client_examples/backchannel.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/client_examples/backchannel.c b/client_examples/backchannel.c
new file mode 100644
index 0000000..643754e
--- /dev/null
+++ b/client_examples/backchannel.c
@@ -0,0 +1,99 @@
+/* A simple example of an RFB client */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <errno.h>
+#include <rfb/rfbclient.h>
+
+static void HandleRect(rfbClient* client, int x, int y, int w, int h) {
+}
+
+/*
+ * The client part of the back channel extension example.
+ *
+ */
+
+#define rfbBackChannel 155
+
+typedef struct backChannelMsg {
+ uint8_t type;
+ uint8_t pad1;
+ uint16_t pad2;
+ uint32_t size;
+} backChannelMsg;
+
+static void sendMessage(rfbClient* client, char* text)
+{
+ backChannelMsg msg;
+ uint32_t length = strlen(text)+1;
+
+ msg.type = rfbBackChannel;
+ msg.size = rfbClientSwap32IfLE(length);
+ if(!WriteToRFBServer(client, (char*)&msg, sizeof(msg)) ||
+ !WriteToRFBServer(client, text, length)) {
+ rfbClientLog("enableBackChannel: write error (%d: %s)", errno, strerror(errno));
+ }
+}
+
+static rfbBool handleBackChannelMessage(rfbClient* client,
+ rfbServerToClientMsg* message)
+{
+ backChannelMsg msg;
+ char* text;
+
+ if(message->type != rfbBackChannel)
+ return FALSE;
+
+ rfbClientSetClientData(client, sendMessage, sendMessage);
+
+ if(!ReadFromRFBServer(client, ((char*)&msg)+1, sizeof(msg)-1))
+ return TRUE;
+ msg.size = rfbClientSwap32IfLE(msg.size);
+ text = malloc(msg.size);
+ if(!ReadFromRFBServer(client, text, msg.size)) {
+ free(text);
+ return TRUE;
+ }
+
+ rfbClientLog("got back channel message: %s\n", text);
+ free(text);
+
+ return TRUE;
+}
+
+static int backChannelEncodings[] = { rfbBackChannel, 0 };
+
+static rfbClientProtocolExtension backChannel = {
+ backChannelEncodings, /* encodings */
+ NULL, /* handleEncoding */
+ handleBackChannelMessage, /* handleMessage */
+ NULL /* next extension */
+};
+
+int
+main(int argc, char **argv)
+{
+ rfbClient* client = rfbGetClient(8,3,4);
+
+ client->GotFrameBufferUpdate = HandleRect;
+ rfbClientRegisterExtension(&backChannel);
+
+ if (!rfbInitClient(client,&argc,argv))
+ return 1;
+
+ while (1) {
+ /* After each idle second, send a message */
+ if(WaitForMessage(client,1000000)>0)
+ HandleRFBServerMessage(client);
+ else if(rfbClientGetClientData(client, sendMessage))
+ sendMessage(client, "Dear Server,\n"
+ "thank you for understanding "
+ "back channel messages!");
+ }
+
+ rfbClientCleanup(client);
+
+ return 0;
+}
+