⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 directed_client.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
字号:
// directed_client.cpp,v 1.8 2003/11/09 20:44:18 dhinton Exp

#include "ace/Log_Msg.h"
#include "ace/SOCK_Dgram.h"
#include "ace/INET_Addr.h"
#include "ace/OS_NS_string.h"
#include "ace/Time_Value.h"

static const u_short PORT = ACE_DEFAULT_SERVER_PORT;

int
main (int argc, char *argv[])
{
  ACE_INET_Addr local ((u_short) 0);
  ACE_INET_Addr remote (PORT,
                        argc > 1 ? argv[1] : "localhost");
  ACE_SOCK_Dgram dgram;

  if (dgram.open (local) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "open"),
                      -1);

  char buf[BUFSIZ];

  /* In order to conform to the "protocol" required by the server, we
    allow the user to specify a signature.  A default matching the
    server's default is also available.  */
  sprintf (buf,
           argc > 2 ? argv[2] : "Hello World!");

  if (dgram.send (buf,
                  ACE_OS::strlen (buf) + 1,
                  remote) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "send"),
                      -1);

  /* Because we may have sent a signature that the server doesn't
    honor, we have to have some way to get out of the recv().  Most
    ACE objects that have potential for infinite blocking give you the
    option of providing a timeout.  recv() is no exception.  Here, we
    construct an ACE_Time_Value representing two seconds and no
    micro-seconds.  If recv() fails to get a response within the two
    seconds, it will return -1.  */
  ACE_Time_Value timeout (2, 0);
  if (dgram.recv (buf,
                  sizeof (buf),
                  remote,
                  0,
                  &timeout) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "recv"),
                      -1);

  /* Note: The fourth parameter to recv() is for flags.  These flags
    are passed directly to the underlying recv() or recvfrom() system
    call.  For Linux, resonable values are: MSG_OOB process
    out-of-band data MSG_PEEK peek at incoming message (but leave it
    in the OS buffers) MSG_WAITALL wait for full request or error See
    your system documentation for the gory details.  */

  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) The server said (%s)\n",
              buf));

  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -