1

How to send mouse position from client A =to=>SERVER=to=>client B ?
Example code below gives me position output every 2 seconds
What is a better/faster way to do this?
NOTICE: using Winsock and cURL gives antivirus malware warning
USAGE: for remote control

Current TEST example of sending mouse position from client A to SERVER to client A:

1.write mouse position
2.store x,y in send.txt file
3.upload sent.txt to server as temp.txt file
4.remove receve.txt if exist //error 80 if not
5.download temp.txt as receve.txt
6.read receve.txt and display coordinates in console

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;

Thank you for your time :)

Ivan
  • 131
  • 7
  • if your code works and you just want to improve your code, then the appropriate site is http://codereview.stackexchange.com/ – bolov Jan 17 '15 at 20:40
  • 1
    One simple improvement would be not saving anything in files, just sending raw bytes of data from the variables themselves (assigning cursor_pos.x to a short, and so for cursor_pos.y as you'll probably never need an actualy long, as the structure defines, and then sending). – Zach P Jan 17 '15 at 20:40
  • Looks like you are using an FTP server as an intermediary. To speed this up you could either write your own server to simply pass on the data to all connected clients or (if you can't change the server) just use to FTP server to discover the other clients and connect to them directly. – Galik Jan 17 '15 at 20:49

1 Answers1

0

You might consider SignalR, it's great for those things. See https://pepitosolis.wordpress.com/2013/12/08/signalr-2-0-persistent-connection-another-example-tracking-your-mouse-pointer/ for an example

vibronet
  • 7,364
  • 2
  • 19
  • 21