GIO示例打开服务器端口? [英] GIO example for opening a server port?

查看:140
本文介绍了GIO示例打开服务器端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能否告诉我是否有任何使用GIO服务器套接字
(我可以打开一个端口并侦听套接字请求的示例)的示例?
我想用它来'远程控制'我的GTK +应用程序。

Can you please tell me if there is any example for using GIO Server Socket (the one which I can open a port and listen on socket requests)? I would like to use it to 'remote-control' my GTK+ application.

推荐答案

我认为你应该做像这样:

I think you should do something like this:

#define MY_PORT 47110

/* Listener callback, this gets called by GTK+ when
 * there's socket activity to handle.
*/
static gboolean cb_listener(GIOChannel *source, GIOCondition condition, gpointer data
{
  switch(condition)
  {
  case G_IO_IN:
    /* There's data to be read. */
    break;
  default:
    /* An error has occured, or socket is closed. */
    return FALSE; /* This tells GIO to remove the source, might be drastic. */
  }
  return TRUE; /* This tells GIO that all is fine. */
}

然后在其他地方(在函数中,也许 main()): / p>

Then elsewhere (in a function, maybe main()):

GSocketListener *listener;

listener = g_socket_listener_new();
g_socket_listener_add_inet_port(listener, MY_PORT, NULL, NULL);
g_io_add_watch(G_IO_CHANNEL(listener), G_IO_IN | G_IO_ERR | G_IO_HUP, cb_listener, NULL);

这篇关于GIO示例打开服务器端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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