在C语言中使用fork()和TCP连接进行设计 [英] Designing using fork() and TCP connection in C

查看:116
本文介绍了在C语言中使用fork()和TCP连接进行设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何设计以下系统有疑问:

I have a question regarding on how to design the following system:

我的系统由侦听环境的多个客户端组成.违反音频阈值时,他们会将信息发送到服务器,该服务器中有孩子在每个连接上进行监听.服务器需要所有客户端的信息来进行必要的计算.

My system is built of several clients listening to an environment. When a audio threshold is breached they send their information to a server, that has children listening on each connection. The server needs information from all the clients to make the necessary calculations.

当前服务器在UNIX中工作,并已建立连接.他们是独立工作的.

Currently the server is working in UNIX and has forked out connections. They are working independently.

我想要做的是告诉父服务器(在服务器中)信息已发送,现在是时候对其进行处理了.我该怎么办?

我正在考虑可能的不同方法:

I'm thinking of possible different ways to do it:

  1. 在Unix中使用signal()以某种方式告诉父母发生了什么事
  2. 转换为线程并使用一些等待和通知功能
  1. Using signal()in Unix to somehow tell the parent that something has happened
  2. Convert to Threads and use some wait and notify functions

最好发送信号,但我无法弄清楚如何有效地执行信号.因为在我的系统中可能发生以下情况:

The signaling is preferable but I cannot figure out how to do it efficiently. Because the following can happen in my system:

  • 如果所有客户端都已成功将信息发送到服务器的子级,那么我该如何高效地告诉父级我已经准备好了呢?不知道/我不确定它将如何处理它们.
  • 服务器可能不会从所有客户端接收信息.因此,父母必须为所有孩子等一会儿,但不要太长.所以我在猜测某种计时器吗?

推荐答案

不使用fork,也不使用信号.使用线程池.

Doen't use fork, and don't use signals. Use a thread pool.

这篇关于在C语言中使用fork()和TCP连接进行设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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