计算机如何建立远程桌面连接
有些时候在外出差,想查看或者调用自己狗窝(宿舍或者家)里的机器的文件,怎么办呢?可以通过远程桌面登录自己个的电脑,利用剪切板的功能便可以实现文件之间的传送。当然,假如家里的电脑没开机,可以让别人帮你开一下机,非常麻烦,有些时候没有人,替我开启电脑。
昨天朋友介绍一个神卓远程桌面,非常好用,远程速度快,粘贴复制不在话下,关键时刻是不掉链子,不像某个软件,经常掉链子,支持手机访问,手机一键远程开机,今天就分享给大家。
大家前往,官网下载吧,然后安装,一直下一步,傻瓜式安装,安装好后把需要被访问的主机,进行绑定,绑定好后,点击检测一下,验证绑定是否,查看网络是否通畅。
如果一切正常说明,绑定成功了,
然后在第二台设备,安装神卓远程,登录自己的账号,就会看到,之前我们绑定的那台主机了,现在点击连接,即可访问了那台主机了,也可以用手机,访问刚刚绑定的那台主机。
试了一下,完全可以,在手机上进行,写代码,超级爽 。
### 它使用Qt的网络模块(Qt Network)来实现服务器和客户端之间的TCP连接,以及QPixmap类来发送和接收屏幕截图
#ifndef SERVER_H
#define SERVER_H
#include <QTcpServer>
#include <QTcpSocket>
#include <QPixmap>
#include <QTimer>
class Server : public QTcpServer
{
Q_OBJECT
public:
explicit Server(QObject *parent = nullptr);
~Server();
private slots:
void onNewConnection();
void onReadyRead();
void onDisconnected();
void onSendScreen();
private:
QTcpSocket *socket;
QPixmap screen;
QTimer *timer;
};
#endif // SERVER_H
#include "server.h"
Server::Server(QObject *parent) :
QTcpServer(parent),
socket(nullptr),
timer(nullptr)
{
if (!listen(QHostAddress::Any, 1234)) {
qWarning("Failed to start server: %s", qPrintable(errorString()));
return;
}
qDebug("Server started on port %d", serverPort());
connect(this, &Server::newConnection, this, &Server::onNewConnection);
timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &Server::onSendScreen);
timer->start(1000);
}
Server::~Server()
{
if (socket) {
socket->close();
delete socket;
}
}
void Server::onNewConnection()
{
if (socket) {
socket->close();
delete socket;
}
socket = nextPendingConnection();
connect(socket, &QTcpSocket::readyRead, this, &Server::onReadyRead);
connect(socket, &QTcpSocket::disconnected, this, &Server::onDisconnected);
qDebug("Client connected: %s", qPrintable(socket->peerAddress().toString()));
}
void Server::onReadyRead()
{
while (socket->bytesAvailable() > 0) {
// Do something with incoming data
// ...
}
}
void Server::onDisconnected()
{
qDebug("Client disconnected: %s", qPrintable(socket->peerAddress().toString()));
socket->deleteLater();
socket = nullptr;
}
void Server::onSendScreen()
{
if (socket && socket->state() == QTcpSocket::ConnectedState) {
screen = QPixmap::grabWindow(QApplication::desktop()->winId());
QByteArray data;
QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly);
screen.save(&buffer, "PNG");
qint64 bytesWritten = socket->write(data);
if (bytesWritten < data.size()) {
qWarning("Failed to send screen data: %lld/%lld bytes written", bytesWritten, data.size());
} else {
qDebug("Screen data sent: %lld bytes", bytesWritten);
}
}
}
#ifndef CLIENT_H
#define CLIENT_H
#include <QTcpSocket>
#include <QPixmap>
#include <QThread>
class Client : public QObject
{
Q_OBJECT
public:
explicit Client(QObject *parent = nullptr);
~Client();
signals:
void screenUpdated(const QPixmap& pixmap);
public slots:
void connectToServer(const QString& host, quint16 port);
private slots:
void onConnected();
void onReadyRead();
void onDisconnected();
private:
QTcpSocket *socket;
QPixmap screen;
};
#endif // CLIENT_H
``
C++11 Web 服务,支持 HTTP GET 请求。以下是一个基本的示例:
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
#include <streambuf>
#include <unordered_map>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
// HTTP Request object
struct Request {
std::string method;
std::string path;
std::string version;
};
// HTTP Response object
struct Response {
std::string status_line;
std::string headers;
std::string body;
};
// Simple HTTP server class
class HttpServer {
public:
HttpServer(int port) : m_port(port) {}
// Start the server
void run() {
// Create a socket for listening
int listen_sock = socket(AF_INET, SOCK_STREAM, 0);
if (listen_sock < 0) {
perror("socket");
return;
}
// Bind the socket to the given port
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(m_port);
addr.sin_addr.s_addr = INADDR_ANY;
if (bind(listen_sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
perror("bind");
close(listen_sock);
return;
}
// Listen for incoming connections
if (listen(listen_sock, 10) < 0) {
perror("listen");
close(listen_sock);
return;
}
// Loop to handle incoming connections
while (true) {
// Accept a new connection
int client_sock = accept(listen_sock, nullptr, nullptr);
if (client_sock < 0) {
perror("accept");
close(listen_sock);
return;
}
// Handle the request
handle_request(client_sock);
// Close the client socket
close(client_sock);
}
// Close the listen socket
close(listen_sock);
}
private:
int m_port; // Port number to listen on
// Handle an incoming request on the given socket
void handle_request(int client_sock) {
// Read the request data from the socket
char buffer[1024];
int n = read(client_sock, buffer, sizeof(buffer));
if (n < 0) {
perror("read");
return;
}
// Parse the request
std::string request_string(buffer, n);
Request request = parse_request(request_string);
// Check if the request method is GET
if (request.method != "GET") {
send_response(client_sock, Response{"HTTP/1.1 405 Method Not Allowed\r\n", "", ""});
return;
}
// Check if the requested file exists
std::string file_path = "." + request.path;
std::ifstream file(file_path);
if (!file.is_open()) {
send_response(client_sock, Response{"HTTP/1.1 404 Not Found\r\n", "", ""});
return;
}
// Read the file contents into a string
std::string file_contents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
// Send the file contents as the response body
send_response(client_sock, Response{"HTTP/1.1 200 OK\r\n", "Content-Type: text/plain\r\n", file_contents});
}
// Parse an HTTP request string into a Request object
Request parse_request(const std::string& request_string) {
Request request;
std::