什么是实现跨平台,多线程服务器在C / C ++的最好方法? [英] What is the best way to implement a cross-platform, multi-threaded server in C/C++?

查看:184
本文介绍了什么是实现跨平台,多线程服务器在C / C ++的最好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发团队我已经给写一个服务器,与我们的产品整合的挑战工作的一部分。我们有一些低级别的传感器设备提供一个C SDK,我们希望被人们收集数据交付使用网络共享。听起来很简单,不是吗?有人的传感器装置连接到他们的机器在建筑物的一个部分,并运行我们的服务器,从而与网络的其余部分共享设备(多个)。然后,客户端将通过我们的应用程序从设备连接到该服务器并收集传感器读数。

Part of the development team I work with has been given the challenge of writing a server for integration with our product. We have some low-level sensor devices that provide a C SDK, and we want to share them over a network for use by people collecting data. Sounds simple, right? Someone would connect a sensor device to their machine in one part of the building and run our server, thus sharing the device(s) with the rest of the network. Then a client would connect to that server via our application and collect sensor readings from the device.

我创建了一个简单的,语言无关的网络协议,并在Java参考实现。问题是创建将与我们的设备上工作的实现,只提供C写的我们想这样做的SDK以下内容:

I created a simple, language-agnostic network protocol, and a reference implementation in Java. The problem is creating an implementation that will work with our devices that only provide an SDK written in C. We were thinking of doing the following:


  1. 创建收集轮询线程和最新的读数每个连接的设备储存。

  2. 使用多线程服务器分拆每个传入的连接到工作线程。

  3. 当一个工作线程接收对传感器读数的请求时,由轮询螺纹最近收集到的值被发送回客户端。

这是一个很大的线程,特别是在C.因此,审查的总体要求是:

That's a lot of threading, especially in C. So, to review, the general requirements are:


  • 运行在Windows XP / Vista中,Linux和OS X光机

  • 用C或C ++与C SDK进行互动,我们有

  • 接受可变数量的并发连接(工作线程)

  • 必须使用线程,不分叉(不想处理IPC的另一层)

任何人都可以提出一个图书馆和preferably一些例如code得到使用开始?

Can anyone suggest a library and preferably some example code to get use started?

推荐答案

我用的 Boost.Thread &安培; Boost.Asio的构建一个多线程的服务器上Windows和放大器; Linux系统。该教程可以轻松上手。

I've used Boost.Thread & Boost.Asio to build a multi-threaded server on Windows & Linux systems. The tutorials made it easy to get started.

这篇关于什么是实现跨平台,多线程服务器在C / C ++的最好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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