1 /* This example shows how to connect to an UltraVNC repeater. */
2
3 #include <rfb/rfb.h>
4
clientGone(rfbClientPtr cl)5 static void clientGone(rfbClientPtr cl)
6 {
7 rfbShutdownServer(cl->screen, TRUE);
8 }
9
main(int argc,char ** argv)10 int main(int argc,char** argv)
11 {
12 char *repeaterHost;
13 int repeaterPort, sock;
14 char id[250];
15 rfbClientPtr cl;
16
17 int i,j;
18 uint16_t* f;
19
20 /* Parse command-line arguments */
21 if (argc < 3) {
22 fprintf(stderr,
23 "Usage: %s <id> <repeater-host> [<repeater-port>]\n", argv[0]);
24 exit(1);
25 }
26 snprintf(id, sizeof(id) - 1, "ID:%s", argv[1]);
27 repeaterHost = argv[2];
28 repeaterPort = argc < 4 ? 5500 : atoi(argv[3]);
29
30 /* The initialization is identical to simple15.c */
31 rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,5,3,2);
32 if(!server)
33 return 0;
34 server->frameBuffer=(char*)malloc(400*300*2);
35 f=(uint16_t*)server->frameBuffer;
36 for(j=0;j<300;j++)
37 for(i=0;i<400;i++)
38 f[j*400+i]=/* red */ ((j*32/300) << 10) |
39 /* green */ (((j+400-i)*32/700) << 5) |
40 /* blue */ ((i*32/400));
41
42 /* Now for the repeater-specific part: */
43 server->port = -1; /* do not listen on any port */
44 server->ipv6port = -1; /* do not listen on any port */
45
46 sock = rfbConnectToTcpAddr(repeaterHost, repeaterPort);
47 if (sock < 0) {
48 perror("connect to repeater");
49 return 1;
50 }
51 if (write(sock, id, sizeof(id)) != sizeof(id)) {
52 perror("writing id");
53 return 1;
54 }
55 cl = rfbNewClient(server, sock);
56 if (!cl) {
57 perror("new client");
58 return 1;
59 }
60 cl->reverseConnection = 0;
61 cl->clientGoneHook = clientGone;
62
63 /* Run the server */
64 rfbInitServer(server);
65 rfbRunEventLoop(server,-1,FALSE);
66
67 return 0;
68 }
69