简体   繁体   English

如何在服务器端(在我的特定情况下)验证用户请求?

[英]How to validate the user request in the server side (in my specific case)?

In my client server application, the client request the camera server to send one or more images with some given resolution (width x height). 在我的客户端服务器应用程序中,客户端请求摄像机服务器发送一个或多个具有给定分辨率(宽x高)的图像。 I have hard-coded the resolution. 我已经对分辨率进行了硬编码。

Let's say the camera is not capable of taking that specified size of the image the user requests. 假设相机无法拍摄用户要求的指定尺寸的图像。 In that case, the server has to deal with that request and take the appropriate action (eg let the user know that the size is invalid, or input again). 在这种情况下,服务器必须处理该请求并采取适当的措施(例如,让用户知道大小无效或再次输入)。 Can someone give me any hints how do I implement that? 有人可以给我任何提示我该如何实施吗? Or if someone could clue me with any better way of doing it than I am doing it right now. 或者,如果有人可以用比我现在做的更好的方法来提示我。 I may not need any code (if someone can answer with it, its fine), I just require a theoretical explanation. 我可能不需要任何代码(如果有人可以回答它,那很好),我只需要理论上的解释即可。 Thanks for your attention. 感谢您的关注。

My working code [If complete code is necessary, please ask for it]: 我的工作代码[如果需要完整的代码,请提出要求]:

Client: 客户:

   printf("chose resolution\nsmall = 1 \nmedium = 2 \nlarge = 3 \nelse defualt\n  ");
    cin >> res;
    if (res == 1) {
        char rr[10] = { "160x120" };
        strcat(RES, rr); // store the rr (160x120) into RES
    }   else if (res == 2) {
        char rr[10] = { "640x480" };
        strcat(RES, rr);
    }   else if (res == 3) {
        char rr[10] = { "1024x768" };
        strcat(RES, rr);
    }
    else {
        char rr[10] = { "320x200" };
        strcat(RES, rr);
    }

Server: 服务器:

for (;;) {

            recv(sock_CONNECTION,fps_res, sizeof(fps_res),NULL);

            stream = capture_open_stream(IMAGE_JPEG, fps_res);

            for(;;)
            {
            int Sbytes=0;
            frame        = capture_get_frame(stream);
            data = capture_frame_data(frame);

            int size = capture_frame_size(frame);

            send(sock_CONNECTION,(char*)&size,sizeof(int),NULL);
            Sbytes=send(sock_CONNECTION,data, size, NULL);


            capture_frame_free(frame);

            if(Sbytes<0){

            break;

            }

            }
            exit(0);

    }

Get the size of the frame after this line of code and compare with client frame. 在此代码行之后获取框架的大小,并与客户端框架进行比较。 And also check whether you have received a frame or not based original request from client. 还要检查您是否从客户端收到了基于帧的原始请求。

int size = capture_frame_size(frame);

after the above line of code check whether you have received the frame based on original request. 在上面的代码行之后,请检查是否已根据原始请求接收到框架。 If not send a error message to client that frame with requested resolution is not available. 如果未发送错误消息给客户端,则请求分辨率的帧不可用。

Please let me know if not yet clear. 如果还不清楚,请通知我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在这种情况下如何验证用户输入? - How to validate the user input in this case? 如何从客户端找出TCP服务器的状态(在冗余服务器的情况下)? - How to find out a TCP server's status from the client side (In a redundant server case)? 如何创建一个验证 function 来根据特定输入及其定义的正则表达式验证来自用户的输入? - How can I create a validate function that would validate the input from the user based on the specific input and its defined regular expression? 验证用户输入字符串上的大小写模式(isupper / islower) - Validate case pattern (isupper/islower) on user input string 如何验证用户输入的月份输入日期? - How to validate user input for month entry in date? 如何获得属于轮廓特定边的点? - How to get points belonging to a specific side of a contour? 以特定用户身份用完proc com服务器 - Run out of proc com server as specific user 如何检查套接字中的服务器端是否从客户端打开 - how to check that the server side in socket is open from client side 如何为开关盒提供可靠的用户输入? - How to make a robust user input for a switch case? 在QDataWidgetMapper中未提交更改的情况下如何通知用户 - How to notify the user in case of unsubmitted change in QDataWidgetMapper
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM