Questions tagged [recvfrom]

The recvfrom() call is used to receive messages from a socket, and may be used to receive data on a socket whether or not it is connection-oriented.

The recvfrom() call is used to receive messages from a , and may be used to receive data on a socket whether or not it is connection-oriented.

Synopsis

#include <sys/types.h>
#include <sys/socket.h>

ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);

Description

sockfd   -- the socket file descriptor to read from  
buf      -- The pointer to the memory location where the data has to be stored   
len      -- The length of the data to be read  
flags    -- Various flags to modify the socket file descriptor  
src_addr -- The memory location where the source address of the message will be filled  
addrlen  -- addrlen is a value-result argument, which the caller should initialize 
before the call to the size of the buffer associated with src_addr, and modified on
return to indicate the actual size of the source address.

Return Value

recvfrom() return the number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown.

Errors

There are some standard errors generated by the socket layer. Additional errors may be generated and returned from the underlying protocol modules. For the complete list, see the manual pages.

126 questions
0
votes
1 answer

How to save value of buffer from recvfrom() into array?

I am working on BSD sockets and I use this function int recvfrom( int socket , void *buffer , size_t nbytes , int flags , struct sockaddr *sender , int *addrlen) but before printing a message in server I want to save value of buffer in array of…
L.krez
  • 31
  • 5
0
votes
1 answer

Reasons for rare sendto()/recvfrom() issues under Winsock?

We recently observe rare UDP communication issues that show the following symptoms: A socket sendto() call fails with error WSAENOBUFS (10055) A subsequent recvfrom() call on this socket does not receive anything, even though Wireshark shows that…
Daniel Pauli
  • 963
  • 1
  • 7
  • 8
0
votes
1 answer

c++ udp recvfrom eventually hangs over remote connection

I'm writing a client server udp application in c++. The application works correctly when the client and server are running on the same machine, however when I run my client on my laptop and the server on an ec2 instance in AWS, the server receives…
gary69
  • 3,620
  • 6
  • 36
  • 50
0
votes
1 answer

Getting undocumented error code from recvfrom

When attempting to read UDP packets using recvfrom the function returns -1 indicating an error. I of course then call WSAGetLastError to find out what the problem is. The reported error number is 183. I cant seem to find any reference as to what…
cHorse
  • 11
  • 1
  • 8
0
votes
3 answers

C UDP receive socket using MSG_DONTWAIT always fails

I'm working on a UDP client / server couple of applications, and my application which sends commands works excellently - I can monitor what's being sent to the port via nc and hexdump and they decode perfectly. On my application which should be…
trycatch
  • 568
  • 1
  • 8
  • 17
0
votes
1 answer

Why the bytes stream got by python socket.recvfrom is different from that crawled by WireShark?

I used the python socket to send a DNS query packet socket and listen to the response. Finally, I got a DNS response packet by the socket.recvfrom(2048) function as expected. But strangely, where I compared the response packet with the packet…
0
votes
1 answer

UDP - is it possible to receive multiple messages in one receive call?

1. Is it possible to receive multiple messages in one receive call? Sender pseudo-code: target = ("xxx.xxx.xxx.xxx", 1234) sender = new_udp_socket() sender.send("Hello", target) sender.send("World", target) Receiver pseudo-code: receiver =…
David Callanan
  • 5,601
  • 7
  • 63
  • 105
0
votes
1 answer

ICMP RAW Socket Incomplete Receive

I have implemented a RAW Socket in linux to send and receive ICMP Packets, I have created RAW Socket using socket(AF_INET, SOCK_RAW, IPPROTO_ICMP) and start receiving the Packets using recvfrom. Initially i was receiving the packets with buffer len…
soni
  • 77
  • 1
  • 9
0
votes
1 answer

Sockets, client server communication using SOCK_DGRAM, epoll

I'm trying to write a program with AF_INET, SOCK_DGRAM, where client connects to server sends it message "First message" and then the server responds to client with "Second message". Q1: In my code server receives "First message", however client…
grzegorzs
  • 486
  • 5
  • 11
0
votes
0 answers

socket.recvfrom() works with one type of UDP stream, but not the other

I know there are a couple of questions out there that already discuss the issue of the recvfrom function hanging, however, I haven't been able to find a question/response that has led me to a solution. My setup (kind of hacky) In my setup I have a…
0
votes
1 answer

recvfrom unexpected error: Invalid argument

I'm writing a server-client application using UDP protocol. When I run the recvfrom I get the following error and I really can't understand why: recvfrom: Invalid argument Here's what I assumed is the code relative to this error: #define CLIE_PORT…
Robb1
  • 4,587
  • 6
  • 31
  • 60
0
votes
1 answer

recvfrom: Resource temporarily unavailable. Why?

I'm running this piece of code several times (for a non-blocking recvfrom on a UDP socket): struct timeval read_timeout; read_timeout.tv_sec = 0; read_timeout.tv_usec = 1000; setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &read_timeout, sizeof…
Robb1
  • 4,587
  • 6
  • 31
  • 60
0
votes
0 answers

C UDP read and recv are breaking my code

So I'm working with UDP sockets and poll(), trying to be able to wait for connections and read input at the same time, but I'm coming up with the weirdest error and I have no idea how to handle it. Here's the part of my code that's causing…
mmaron
  • 11
  • 4
0
votes
0 answers

non blocking tcp client assembly

I am trying to create a tcp client for exchange data. The client should send the message first. If the message was correct, and the user has been property authorized, the system replies with the message 'Ask', confirming that the session has been…
0
votes
2 answers

Why would recvfrom() used on a stream socket return a zero address and port?

I am using a Linux system, not a Windows system. I've posted some code, below. Please bear in mind that this code was never intended to be "production quality." #include #include #include #include #include…
LiamF
  • 523
  • 3
  • 13
1 2 3
8 9