dongsi7067 2013-04-01 11:28
浏览 39

服务器上的临时存储

I'm looking for an efficient and secure way to store small amount of user data like a line of text, for an indefinite period of time. The scenario: One client 'A' sends some data to another client 'B' , asynchronously via a server 'S'. For simplicity, consider the data to be a single line of text. Now, this data would be delivered to client 'B' by server 'S' , only when B asks for it. So until that time Server 'S' has to store this data.

For a simple demo, I implemented it very crudely as follows:
Client 'A' does a POST request with XMLHttpRequest, sending the text to 'S' as follows

    xhr.open("POST",url+"?sentText=text"); //url points to a php file on S
    xhr.send(); 

The PHP code then saves the received text to a file as follows:

    <?php
    $selected = $_GET["sentText"];
    $writefile = "text.txt";
    $fh = fopen($writefile,'w');
    fwrite($fh,$selected);
    fclose($fh);
    ?>

Later, after any amount of time, B asks for the text in this file,using BufferedInputStream as follows:

    URL fileurl = new URL("url/text.txt");
    BufferedReader in = new BufferedReader(new InputStreamReader(fileurl.openStream()));
    while((tmpReceived = in.readLine())!=null){
       received = tmpReceived;
    }

This demo works properly, but this is just a demo. However, if this were to be a full scale real world application with millions of users, how would I implement the following:

The part where server S stores the text. Obviously, I can't save the text as plain text in a file, as it would breach my users' privacy. And it would also be ineffecient when there are millions of users. How do commercial services like Dropbox achieve this?

To keep things simple, I just need to know how to do this for text, then I can extrapolate to other types possibly.

Thanks a lot!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 易康econgnition精度验证
    • ¥15 线程问题判断多次进入
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致