在服务器中使用WSAAsyncSelect()函数来处理多个客户端 [英] using WSAAsyncSelect() function in server to handle multiple clients

查看:180
本文介绍了在服务器中使用WSAAsyncSelect()函数来处理多个客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器端有一个异步套接字。只要在套接字上有要读取或写入的内容,就会生成窗口的消息。现在,服务器上只有一个异步套接字可以处理多个客户端的请求。但如果客户数超过,我不确定这是否有效。如果我需要处理40个客户端,是否需要在服务器端创建40个异步套接字来同时处理40个客户端中的每个客户端的请求?我不确定如何将此单服务器单客户端应用程序扩展到多个客户端应用程序。任何人都可以给我一些指导如何前进?下面是我在服务器端使用单个异步套接字完成的代码:

I have a single asynchronous socket at my server side. whenever there is something to be read or written on the socket, a window''s message is generated. Right now there is only one single asynchronous socket on the server that handles requests of more than one client I guess. But I am not sure will this work if number of clients exceed. If I need to handle 40 clients, do I need to create 40 asynchronous sockets at server side to handle request of each of the 40 clients simultaneoulsy? I am not sure how to extend this single server single client application to multiple clients application. Can anybody give me some guidlines how to move forward? below is the code I done at server side with a single asynchronous socket:

WSAAsyncSelect (socketIdentifier, hwnd, MY_MESSAGE_NOTIFICATION, FD_READ | FD_CONNECT | FD_CLOSE | FD_ACCEPT); //Making the socket Asynchronous
   while(GetMessage(&Msg, NULL, 0, 0) > 0) //Waiting for windows messages
      {         
         TranslateMessage(&Msg);
         DispatchMessage(&Msg);
      }
   return Msg.wParam;


    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
       switch(msg)
          {
           case MY_MESSAGE_NOTIFICATION: //Window message generated by asynchronous socket.
            {
             switch (lParam) //If so, which one is it?
                {
                case FD_ACCEPT:
                    //Connection request was made
                    break;

                case FD_CONNECT:
                    //Connection was made successfully
                    break;

                case FD_READ:
                   receiveAtSocket();
                break;

                case FD_CLOSE:
                    //Lost the connection
                 break;
                }
            }
            break;
        }
    }

推荐答案

此问题已在您之前的查询将40个套接字绑定到40个不同的IP地址 [ ^ ]。如果您有进一步的信息,请回复给您答案的人。
This question has already been answered in your previous query at Binding 40 Sockets to 40 different IP addresses[^]. If you have further information then please respond to the person who gave you the answer.


这篇关于在服务器中使用WSAAsyncSelect()函数来处理多个客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆