【问题标题】:Sending mouse position over internet通过互联网发送鼠标位置
【发布时间】:2015-01-17 20:33:42
【问题描述】:

如何从客户端 A =to=>SERVER=to=>客户端 B 发送鼠标位置?
下面的示例代码每 2 秒提供一次位置输出
有什么更好/更快的方法来做到这一点?
注意:使用 Winsock 和 cURL 会发出防病毒恶意软件警告
用途:用于遥控

当前将鼠标位置从客户端 A 发送到 SERVER 到客户端 A 的 TEST 示例:

1.写鼠标位​​置
2.将 x,y 存储在 send.txt 文件中
3.将 sent.txt 作为 temp.txt 文件上传到服务器
4.remove receve.txt 如果存在 //如果不存在则错误 80
5.将 temp.txt 下载为 receve.txt
6.读取receve.txt并在控制台显示坐标

int x,y; //positions
LPCWSTR s=L"C://Documents and Settings//Administrator//Desktop//c++//FTP//send.txt";//location of file for sending
LPCWSTR r=L"C://Documents and Settings//Administrator//Desktop//c++//FTP//receve.txt";//location of received file
POINT cursor_pos;//for cursor position

HINTERNET hInternet;
    HINTERNET hFtpSession;
    hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    if (hInternet == NULL)
    {
        cout << "Error: " << GetLastError();
    }
    else
    {

        hFtpSession = InternetConnect(hInternet, L"www.test.net", INTERNET_DEFAULT_FTP_PORT, L"user", L"pass", INTERNET_SERVICE_FTP, 0, 0);
        if (hFtpSession == NULL)//not connect
        {
            cout << "Error: " << GetLastError();
        }
        else
        {    


            for(;;){
//file input
fstream inp;
inp.open(s);

GetCursorPos(&cursor_pos);
inp<<cursor_pos.x<<" "<<cursor_pos.y<<endl;//write curent position



inp.close();

           //UPLOADING
            if (!FtpPutFile(hFtpSession, s, L"//public_html//test//temp.txt", FTP_TRANSFER_TYPE_BINARY, 0))
            {
                cout << "ErrorPutFile: " << GetLastError();
                return 0;
            }


            remove("C://Documents and Settings//Administrator//Desktop//c++//FTP//receve.txt");//error 80 if file exist so remove it
           //DOWNLOADING
            if(!FtpGetFile(hFtpSession,L"//public_html//test//temp.txt",r,TRUE,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_BINARY,0))
            {

            cout <<"ErrorGetFile"<<GetLastError();
            return 0;
            }//DELETING 
           if(!FtpDeleteFile(hFtpSession,L"//public_html//test//temp.txt")){

            cout <<"ErrorGetFile"<<GetLastError();
            return 0;

           }



ifstream outp(r);

while(outp>>x>>y){
cout<<"X: "<<x<<" "<<"Y:"<<y<<endl;//read coordinates

}
outp.close();

            }



        }
    }

return 0;

感谢您的宝贵时间:)

【问题讨论】:

  • 如果您的代码有效并且您只是想改进您的代码,那么合适的站点是codereview.stackexchange.com
  • 一个简单的改进是不在文件中保存任何东西,只是从变量本身发送原始数据字节(将 cursor_pos.x 分配给一个短字节,对于 cursor_pos.y,你可能永远不会需要一个实际上很长,如结构定义,然后发送)。
  • 看起来您正在使用 FTP 服务器作为中介。为了加快速度,您可以编写自己的服务器来简单地将数据传递给所有连接的客户端,或者(如果您无法更改服务器)只需使用 FTP 服务器来发现其他客户端并直接连接到它们。跨度>

标签: c++ wininet winhttp remote-control


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    相关资源
    最近更新 更多