sendto

UDP non-blocking socket on a real-time OS: sendto() and recvfrom() can return with partial message?

百般思念 提交于 2021-02-08 04:38:47
问题 This is my first message here. I'm working with a non-blocking UDP socket on a real-time OS (OnTime and VxWorks). I have read the documentation and some forums but I have some doubts about 'atomicity' of sendto() and recvfrom() functions: sendto() returns the number of bytes enqueued or error. Is it possible that it's less then the input buffer length? Maybe the output buffer has not enough free space and just few bytes are enqueued... recvfrom() returns the number of byte received or error.

unix socket error 14: EFAULT (bad address)

 ̄綄美尐妖づ 提交于 2021-02-07 11:17:48
问题 I have a very simple question, but I have not managed to find any answers to it all weekend. I am using the sendto() function and it is returning error code 14: EFAULT. The man pages describe it as: "An invalid user space address was specified for an argument." I was convinced that this was talking about the IP address I was specifying, but now I suspect it may be the memory address of the message buffer that it is referring to - I can't find any clarification on this anywhere, can anyone

UDP socket sendto() functions

依然范特西╮ 提交于 2021-02-07 04:11:50
问题 I get an error if I want to write on my udp socket like this. According to the docu there shouldn't be a problem. I don't understand why bind() works well in the same way but sendto() fails. udp_port = 14550 udp_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) udp_server.bind(('127.0.0.1', udp_port)) udp_clients = {} Error: udp_server.sendto('', ('192.0.0.1', 14550) ) socket.error: [Errno 22] Invalid argument 回答1: The error says that you have an invalid argument. When reading your

UDP socket sendto() functions

戏子无情 提交于 2021-02-07 04:11:00
问题 I get an error if I want to write on my udp socket like this. According to the docu there shouldn't be a problem. I don't understand why bind() works well in the same way but sendto() fails. udp_port = 14550 udp_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) udp_server.bind(('127.0.0.1', udp_port)) udp_clients = {} Error: udp_server.sendto('', ('192.0.0.1', 14550) ) socket.error: [Errno 22] Invalid argument 回答1: The error says that you have an invalid argument. When reading your

Combining sento() write writev()?

大兔子大兔子 提交于 2020-07-21 04:09:07
问题 I've set a udp socket and call sendto() with a different recipient at each call. I would like to use writev() in order to benefit scater/gather io but writev() does not allows me to specify the recipient addr/port as in sendto(). Any suggestions? 回答1: You can use writev to send a coalesced set of buffers to a single end point if you use connect to specify the end point beforehand. From the (OSX) manpage for connect(2) : datagram sockets may use connect() multiple times to change their

UDP中的sendto 与recvfrom

醉酒当歌 提交于 2020-03-23 05:59:38
sendto 头文件 : #include <sys/types.h> #include <sys/socket.h> 定义函数 : int sendto(int s, const void * msg, int len, unsigned int flags, const struct sockaddr * to, int tolen); 参数说明 : s:一个标识套接口的描述字。 buf:包含待发送数据的缓冲区。 len:buf缓冲区中数据的长度。 flags:调用方式标志位。 to:(可选)指针,指向目的套接口的地址。 tolen:to所指地址的长度。 函数说明 : sendto() 用来将数据由指定的socket 传给对方主机. 参数s 为已建好连线的socket, 如果利用UDP协议则不需经过连线操作. 参数msg 指向欲连线的数据内容, 参数flags 一般设0, 详细描述请参考send(). 参数to 用来指定欲传送的网络地址, 结构sockaddr 请参考bind(). 参数tolen 为sockaddr 的结果长度. 返回值 : 成功则返回实际传送出去的字符数, 失败返回-1, 错误原因存于errno 中. 错误代码 : 1、EBADF 参数s 非法的socket 处理代码. 2、EFAULT 参数中有一指针指向无法存取的内存空间. 3、WNOTSOCK

linux网络多线程编程实例

让人想犯罪 __ 提交于 2020-02-24 14:43:06
用的是UDP方式。 服务器能同时接受十个客户端,各个客户端可以相互点对点通讯;可以对所有连到 服务器的客户端广播;也可以和服务器通讯。服务器也可以广播。 运行时你要先看懂源代码中的命令: "/w " 广播 ; "/s n " 对某个客户端; "/sv "对服务器; 命令是引号中的部分,注意空格。 服务端代码: #include<sys/stat.h> #include<fcntl.h> #include<unistd.h> #include<sys/types.h> #include<sys/socket.h> #include <sys/wait.h> #include <netinet/in.h> #include<arpa/inet.h> #include<stdio.h> #include<string.h> #include<stdlib.h> #include <pthread.h> #define PORT 8889 #define max_size 256 ///////////////////////////////////////////////////////// int sockfd,sockfd2[10],ret,i=0,j,flag=0; struct sockaddr_in addr; struct sockaddr_in addr2[10]; int

UDP编程中client和server中使用recvfrom和sendto的区别

 ̄綄美尐妖づ 提交于 2020-02-18 07:54:15
client中: sendto(sfd,buf,strlen(buf),0,(struct sockaddr *)&saddr,len); recvfrom(sfd,buf,sizeof(buf),0,NULL,NULL); server中: recvfrom(fd,buf,sizeof(buf),0,(struct sockaddr *)&caddr,&len); 将网络字节序的IP地址转换成字符串输出 // inet_ntoa : struct ip -> char *ip char *paddr = NULL; paddr = inet_ntoa(caddr.sin_addr); printf("client[%s] say:%s\n",paddr,buf); sendto(fd,buf,strlen(buf),0,(struct sockaddr *)&caddr,len); struct sockaddr_in saddr; socklen_t len = sizeof(saddr); sendto最后两个参数是(struct sockaddr *)&saddr【 saddr 是自己 新建的sockaddr_in型的变量】, len【len 是socklen_t型的变量 其值为sizeof(saddr)】在client和server的编程中相似。