使用UNIX中的套接字的IPC中数据大小的最大限制 [英] Maximum limit on size of data in IPC using sockets in unix

查看:86
本文介绍了使用UNIX中的套接字的IPC中数据大小的最大限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在2个不同进程之间使用AF_UNIX,SOCK_STREAM套接字进行IPC.客户端正在通过服务器提取和处理的套接字发送数据.使用以下命令,客户端写入套接字的每个数据块的大小大约为13 KB:

I am using AF_UNIX,SOCK_STREAM socket for IPC between 2 different processes. The client is sending data over the socket which the server picks up and processes. The size of each block of data that the client writes to the socket is roughly 13 kilobytes using the following command:

Send Command in client : send(s, txPackDisp, sizeof(float)*PACKET_LENGTH, 0);

但是,当我使用以下命令在服务器上接收到数据时:

However, when I receive the data on the server using the following command :

Receive command in server : recv(s, bfoData, PACKET_LENGTH*sizeof(float),0);

每次收到的数据只是我发送的数据的一部分(最后有很多零,事实并非如此).

the data received everytime is only partial of what I send (there are a lot of zeros in the end which should not be the case).

所以我的问题是:

  1. 我可以通过AF_UNIX,SOCK_STREAM套接字发送的数据大小的最大限制是否有限制(据我所读,我认为没有)

  1. Is there a limit on the maximum limit on the size of data that I can send over the AF_UNIX,SOCK_STREAM socket ( from what I have read , I dont think there is )

套接字在传输时是否将数据分解成较小的块?如果是这种情况,我需要像现在这样单独地或作为单个块接收较小的块.

Does the socket break up the data into smaller blocks when transferring and if thats the case do I need to receive the smaller blocks individually or as single block like I am doing right now.

在这里使用AF_UNIX,SOCK_DGRAM套接字会更好.

Will it be better to use AF_UNIX,SOCK_DGRAM socket here.

PS:此问题中可以看到服务器和客户端主要功能的源代码:

P.S : The source code for the main functions for the server and client can be seen in this question : IPC using Unix Domain Sockets

推荐答案

Q1) Is there a limit on the maximum limit on the size of data that I can send over the AF_UNIX,SOCK_STREAM socket ( from what I have read , I don't think there is )

您是正确的. SOCK_STREAM没有实际限制.

You are correct. There is no real limit for SOCK_STREAM.

Q2 a) Does the socket break up the data into smaller blocks when transferring

您是正确的.流由发送器和接收器协商成可管理大小的数据包.

You are correct. The stream is broken up into a manageable sized packets, negotiated by both the transmitter and the receiver.

Q2 b) and if thats the case do I need to receive the smaller blocks individually or as single block like I am doing right now.

您无需执行任何操作.流在传输时在另一端重新组装.

You needn't do anything. The stream is reassembled on the other end, just as it was transmitted.

Q3) Will it be better to use AF_UNIX,SOCK_DGRAM socket here.

不. 除非您需要全面了解数据包大小协商,检查丢失的数据包并重新发送它们,确保正确管理乱序接收的数据包等,否则

这篇关于使用UNIX中的套接字的IPC中数据大小的最大限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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