vnc 修改端口5901为1521
发表人:ignu | 发表时间: 20xx年一月15日, 10:25
5901端口没有开放,只开放的数据库1521端口,数据库还没有安装前可以先借用1521使用VNC。
编辑vncserver vi /usr/bin/vncserver
$vncPort = 5900 + $displayNumber;
为
$vncPort = 1520 + $displayNumber;
vi /usr/bin/vncserver
$vncPort = 1520 + $displayNumber;
$desktopLog = "$vncUserDir/$host:$displayNumber.log";
unlink($desktopLog);
# Make an X server cookie - use as the seed the sum of the current time, our
# PID and part of the encrypted form of the password. Ideally we'd use # /dev/urandom, but that's only available on Linux.
srand(time+$$+unpack("L",`cat $vncUserDir/passwd`));
$cookie = "";
for (1..16) {
$cookie .= sprintf("%02x", int(rand(256)) % 256);
}
system("xauth -f $xauthorityFile add $host:$displayNumber . $cookie"); system("xauth -f $xauthorityFile add $host/unix:$displayNumber . $cookie");
# Now start the X VNC Server
$cmd = "Xvnc :$displayNumber";
"/usr/bin/vncserver" 566 lines, 13687 characters root@IDD-SVR # vncserver -kill :1
Killing Xvnc process ID 19948 root@IDD-SVR # vncserver
New 'X' desktop is IDD-SVR:1
Starting applications specified in //.vnc/xstartup
Log file is //.vnc/IDD-SVR:1.log root@IDD-SVR # vi //.vnc/IDD-SVR:1.log
"//.vnc/IDD-SVR:1.log" 10 lines, 565 characters
15/01/10 10:10:24 Xvnc version 3.3.4 - built Sep 20 2002 15:28:59 15/01/10 10:10:24 Copyright (C) 2002 RealVNC Ltd.
15/01/10 10:10:24 Copyright (C) 1994-2000 AT&T Laboratories Cambridge. 15/01/10 10:10:24 All Rights Reserved.
15/01/10 10:10:24 See for information on VNC 15/01/10 10:10:24 Desktop name 'X' (IDD-SVR:1)
15/01/10 10:10:24 Protocol version supported 3.3
15/01/10 10:10:24 Listening for VNC connections on TCP port 1521 15/01/10 10:10:24 Listening for HTTP connections on TCP port 5801 15/01/10 10:10:24 URL http://IDD-SVR:5801
第二篇:vnc代码
vnc
win-hook + event-simulate + gdi-bitmap-capture(delay send) + libjpeg + socket
*******************************************************************************************************************
VNC的图像更新机制核心为,桌面区域更新记录策略和更新区域通知策略。
桌面更新区域记录主要是通过hooks记录桌面上变化的矩形区域,
只记录更新的矩形区不记录具体更新的数据。
更新区域记录步骤大致如下:
1.wm_hooks截获桌面变化的相关消息,并转化为自定义的消息发送给WMHooksThread线程处理。
2. WMHooksThread 中用SimpleUpdateTracker new_changes记录新的更新区域.
3.把SimpleUpdateTracker new_changes更新拷贝到SDisplay中。
4.每次要发送桌面更新的时候,把SDisplay中记录的更新区域传给VNCServerST 对象中。 更新区域的通知主要有poll和push两种机制。push是服务器每隔10ms检查有没有更新,如果有更新则主动把更新推送给客户端,
poll机制则是客户端主动请求更新,客户端通过发送framebufferupdate请求某一个区域更新,服务器处理该消息发送相应的更新。
********************************************************************************************************************
详细分析如下:
1.Wm_hooks截获消息并转化为自定义的消息发送给WMHooksThread线程处理。
Wm_hooks自定义的消息:
UINT WM_HK_WindowChanged = RegisterWindowMessage(_T("RFB.WM_Hooks.WindowChanged"));
UINT WM_HK_WindowClientAreaChanged = UINT WM_HK_WindowBorderChanged = RegisterWindowMessage(_T("RFB.WM_Hooks.WindowBorderChanged"));
UINT WM_HK_RectangleChanged = RegisterWindowMessage(_T("RFB.WM_Hooks.RectangleChanged"));
UINT WM_HK_CursorChanged = RegisterWindowMessage(_T("RFB.WM_Hooks.CursorChanged"));
钩子截获到消息以后,把它转化为自定义的消息,然后发送给WMHooksThread线程处理,消息转化如下:
边框更新消息:WM_NCPAINT,WM_NCACTIVATE
客户区域更新消息:BM_SETCHECK, BM_SETSTATE,EM_SETSEL,WM_CHAR,WM_ENABLE,WM_KEYUP,WM_LBUTTONUP,WM_MBUTTONUP,
WM_PALETTECHANGED,WM_RBUTTONUP,WM_SYSCOLORCHANGE,WM_SETTEXT。
窗口改变消息:WM_HSCROLL,WM_VSCROLL,482,485。
矩形区更新消息:WM_DESTROY
窗口客户区消息:WM_PAINT
鼠标消息:WM_NCMOUSEMOVE,WM_MOUSEMOVE
2 . WMHooksThread 中用SimpleUpdateTracker new_changes记录新的更新区域
WMHooksThread::run() 函数中先判断出矩形区域改变的大小,然后调用NotifyHooksRegion(const Region& r)把改变的区域记录到SimpleUpdateTracker new_changes中。
NotifyHooksRegion(const Region& r) {
Lock l(hook_mgr_lock);
std::list<WMHooks*>::iterator i;
for (i=hooks.begin(); i!=hooks.end(); i++) {
(*i)->new_changes.add_changed(r);
if (!(*i)->notified) {
(*i)->notified = true;
PostMessage((*i)->getHandle(), WM_USER, 0, 0); // 把消息通知到clipper见下面一个处理函数
}
}
}
3.把更新区域拷贝到SDisplay中
rfb::win32::WMHooks::processMessage(UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_USER:
{
Sleep(0);
Lock l(hook_mgr_lock);
notified = false;
new_changes.get_update(*clipper); //把更新通知到clipper中
new_changes.clear();
}
break;
}
return MsgWindow::processMessage(msg, wParam, lParam);
}
Cliper在下面设置
rfb::win32::WMHooks::setUpdateTracker(UpdateTracker* ut) {
if (clipper) delete clipper;
clipper = new ClippedUpdateTracker(*ut);
clipper->set_clip_region(clip_region);
return AddHook(this);
}
UpdateTracker* ut 为void SDisplay::start(VNCServer*vs)中设置core->wm_hooks.setUpdateTracker(this);
4.把SDisplay中记录的数据传给VNCServerST 对象 core->using_hooks =
在 SDisplay::processEvent(HANDLE event) {
try_update = flushChangeTracker() || try_update; //把变化的区域拷贝到VNCServerST中
if (try_update)
server->tryUpdate(); //把更新发送给服务器
}
flushChangeTracker()实现如下:
bool SDisplay::flushChangeTracker() {
if (change_tracker.is_empty())
return false;
change_tracker.translate(screenRect.tl.negate());
change_tracker.get_update(*server); //server 实际指向VNCServerST 对象该函数把SDisplay中的更新拷贝到VNCServerST中。
change_tracker.clear();
return true;
}
两种数据更新方式:Push机制和Pull机制
Push:
SdisplayCore 中IntervalTimer cursorTimer定时器,每隔10ms尝试着检查一下是否有更新,如果有更新就发送更新给客户端。
第一步:
LRESULT SDisplayCore::processMessage(UINT msg, WPARAM wParam, LPARAM lParam) {
case TIMER_CURSOR:
display->triggerUpdate(); //SDisplay* display;
}
第二步:
void SDisplay::triggerUpdate() {
if (core)
SetEvent(updateEvent); //使事件对象为受信状态
}
第三步:
SDisplay::processEvent(HANDLE event) {
if (event == updateEvent) {
if (try_update)
server->tryUpdate(); // VNCServer* server指针 指向子类VNCServerST
}
}
第四步:向每一个连接的客户端发送更新
void VNCServerST::tryUpdate()
{
std::list<VNCSConnectionST*>::iterator ci, ci_next;
for (ci = clients.begin(); ci != clients.end(); ci = ci_next) {
ci_next = ci; ci_next++;
(*ci)->writeFramebufferUpdateOrClose();
}
}
第五步:
void VNCSConnectionST::writeFramebufferUpdateOrClose()
{
try {
writeFramebufferUpdate();
} catch(rdr::Exception &e) {
close(e.str());
}
}
第六步:SimpleUpdateTracker updates对象记录更新的区域,如果屏幕有更新则发送更新
void VNCSConnectionST::writeFramebufferUpdate(){
if (!update.is_empty() || writer()->needFakeUpdate() || drawRenderedCursor) {
int nRects = update.numRects() + (drawRenderedCursor ? 1 : 0);
writer()->writeFramebufferUpdateStart(nRects);
Region updatedRegion;
writer()->writeRects(update, &image_getter, &updatedRegion); // SmsgWriter *
updates.subtract(updatedRegion);
if (drawRenderedCursor)
writeRenderedCursorRect();
writer()->writeFramebufferUpdateEnd();
requested.clear();
}
}
第七步:利用RFB协议发送更新
void SMsgWriterV3::writeFramebufferUpdateStart(int nRects)
{
startMsg(msgTypeFramebufferUpdate);
os->pad(1);
if (wsccb) nRects++;
if (needSetDesktopSize) nRects++;
os->writeU16(nRects);
nRectsInUpdate = 0;
nRectsInHeader = nRects;
if (wsccb) {
wsccb->writeSetCursorCallback();
wsccb = 0;
}
}
Poll机制:客户端通过发送更新请求,请求更新某一个区域。
第一步:读取到一个更新某一个区域的请求
void SMsgReaderV3::readMsg()
{
case msgTypeFramebufferUpdateRequest: readFramebufferUpdateRequest(); break;
}
第二步:调用网络事件处理对象handler处理事件
void SMsgReader::readFramebufferUpdateRequest()
{
bool inc = is->readU8();
int x = is->readU16();
int y = is->readU16();
int w = is->readU16();
int h = is->readU16();
endMsg();
handler->framebufferUpdateRequest(Rect(x, y, x+w, y+h), inc);//handler 为 SMsgHandler* handler指针 是指向VNCSConnectionST对象
}
第三步:
void VNCSConnectionST::framebufferUpdateRequest(const Rect& r,bool incremental)
{
if (!(accessRights & AccessView)) return;
SConnection::framebufferUpdateRequest(r, incremental);
Region reqRgn(r);
requested.assign_union(reqRgn);
if (!incremental) {
updates.add_changed(reqRgn);
server->comparer->add_changed(reqRgn);
}
writeFramebufferUpdate();
}
第四步:SimpleUpdateTracker updates对象记录更新的区域,如果屏幕有更新则发送更新
void VNCSConnectionST::writeFramebufferUpdate(){
if (!update.is_empty() || writer()->needFakeUpdate() || drawRenderedCursor) {
int nRects = update.numRects() + (drawRenderedCursor ? 1 : 0);
writer()->writeFramebufferUpdateStart(nRects);
Region updatedRegion;
writer()->writeRects(update, &image_getter, &updatedRegion); // SmsgWriter *
updates.subtract(updatedRegion);
if (drawRenderedCursor)
writeRenderedCursorRect();
writer()->writeFramebufferUpdateEnd();
requested.clear();
}
}
第五步:利用RFB协议发送更新
void SMsgWriterV3::writeFramebufferUpdateStart(int nRects)
{
startMsg(msgTypeFramebufferUpdate);
os->pad(1);
if (wsccb) nRects++;
if (needSetDesktopSize) nRects++;
os->writeU16(nRects);
nRectsInUpdate = 0;
nRectsInHeader = nRects;
if (wsccb) {
wsccb->writeSetCursorCallback();
wsccb = 0;
}
}