Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
libvncserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
libvncserver
Commits
11fc700c
Commit
11fc700c
authored
Oct 06, 2005
by
dscho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add BackChannel extension example
parent
5c1fdb47
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
1 deletion
+114
-1
Makefile.am
examples/Makefile.am
+1
-1
backchannel.c
examples/backchannel.c
+113
-0
No files found.
examples/Makefile.am
View file @
11fc700c
...
...
@@ -14,6 +14,6 @@ noinst_HEADERS=radon.h
noinst_PROGRAMS
=
example pnmshow regiontest pnmshow24 fontsel
\
vncev storepasswd colourmaptest simple simple15
$(MAC)
\
$(FILETRANSFER)
$(FILETRANSFER)
backchannel
examples/backchannel.c
0 → 100644
View file @
11fc700c
#include <rfb/rfb.h>
/*
* This is a simple example demonstrating a protocol extension.
*
* The "back channel" permits sending commands between client and server.
* It works by sending plain text messages.
*
* As suggested in the RFB protocol, the back channel is enabled by asking
* for a "pseudo encoding", and enabling the back channel on the client side
* as soon as it gets a back channel message from the server.
*
* This implements the server part.
*
* Note: If you design your own extension and want it to be useful for others,
* too, you should make sure that
*
* - your server as well as your client can speak to other clients and
* servers respectively (i.e. they are nice if they are talking to a
* program which does not know about your extension).
*
* - if the machine is little endian, all 16-bit and 32-bit integers are
* swapped before they are sent and after they are received.
*
*/
#define rfbBackChannel 155
typedef
struct
backChannelMsg
{
uint8_t
type
;
uint8_t
pad1
;
uint16_t
pad2
;
uint32_t
size
;
}
backChannelMsg
;
rfbBool
enableBackChannel
(
rfbClientPtr
cl
,
void
*
data
,
int
encoding
)
{
if
(
encoding
==
rfbBackChannel
)
{
backChannelMsg
msg
;
const
char
*
text
=
"Server acknowledges back channel encoding
\n
"
;
uint32_t
length
=
strlen
(
text
)
+
1
;
int
n
;
rfbLog
(
"Enabling the back channel
\n
"
);
msg
.
type
=
rfbBackChannel
;
msg
.
size
=
Swap32IfLE
(
length
);
if
((
n
=
rfbWriteExact
(
cl
,
(
char
*
)
&
msg
,
sizeof
(
msg
)))
<=
0
||
(
n
=
rfbWriteExact
(
cl
,
text
,
length
))
<=
0
)
{
rfbLogPerror
(
"enableBackChannel: write"
);
}
return
TRUE
;
}
return
FALSE
;
}
static
rfbBool
handleBackChannelMessage
(
rfbClientPtr
cl
,
void
*
data
,
const
rfbClientToServerMsg
*
message
)
{
if
(
message
->
type
==
rfbBackChannel
)
{
backChannelMsg
msg
;
char
*
text
;
int
n
;
if
((
n
=
rfbReadExact
(
cl
,
((
char
*
)
&
msg
)
+
1
,
sizeof
(
backChannelMsg
)
-
1
))
<=
0
)
{
if
(
n
!=
0
)
rfbLogPerror
(
"handleBackChannelMessage: read"
);
rfbCloseClient
(
cl
);
return
TRUE
;
}
msg
.
size
=
Swap32IfLE
(
msg
.
size
);
if
((
text
=
malloc
(
msg
.
size
))
==
NULL
)
{
rfbErr
(
"Could not allocate %d bytes
\n
"
,
msg
.
size
);
return
TRUE
;
}
if
((
n
=
rfbReadExact
(
cl
,
text
,
msg
.
size
))
<=
0
)
{
if
(
n
!=
0
)
rfbLogPerror
(
"handleBackChannelMessage: read"
);
rfbCloseClient
(
cl
);
return
TRUE
;
}
rfbLog
(
"got message:
\n
%s
\n
"
,
text
);
free
(
text
);
return
TRUE
;
}
return
FALSE
;
}
static
int
backChannelEncodings
[]
=
{
rfbBackChannel
,
0
};
static
rfbProtocolExtension
backChannelExtension
=
{
NULL
,
/* newClient */
NULL
,
/* init */
backChannelEncodings
,
/* pseudoEncodings */
enableBackChannel
,
/* enablePseudoEncoding */
handleBackChannelMessage
,
/* handleMessage */
NULL
,
/* close */
NULL
,
/* usage */
NULL
,
/* processArgument */
NULL
/* next extension */
};
int
main
(
int
argc
,
char
**
argv
)
{
rfbScreenInfoPtr
server
;
rfbRegisterProtocolExtension
(
&
backChannelExtension
);
server
=
rfbGetScreen
(
&
argc
,
argv
,
400
,
300
,
8
,
3
,
4
);
server
->
frameBuffer
=
(
char
*
)
malloc
(
400
*
300
*
4
);
rfbInitServer
(
server
);
rfbRunEventLoop
(
server
,
-
1
,
FALSE
);
return
(
0
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment