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

UDP Socket - Server hanging on recvfrom

I am attempting to implement a client-server network. I am following Beej's Guide to Network Programming My program scans an input from the keyboard, looks up the associated value in an array then sends a GET request to my server via UDP. However,…
Brian
  • 7,098
  • 15
  • 56
  • 73
0
votes
1 answer

UDP Socket: recvfrom() returns -1 (SOCKET_ERROR)

I'm working on a server-client application based on UDP protocols. The server is written in c++ and the client is in C#. On the server side I get the buffer using the recvfrom(): int bufLen = recvfrom(s, buf, 1024, NULL, (sockaddr*)&addr,…
user3530012
  • 720
  • 2
  • 20
  • 37
0
votes
1 answer

recvfrom() gives a bad file descriptor error when used in POSIX thread in C

I am implementing a mini youtube sort of socket interface. The problem comes when receiving data from my subservers in a threaded main_server, that can easily handle multiple subservers. If i join the thread via pthread_join after the thread…
Ali Abbas Jaffri
  • 153
  • 2
  • 15
0
votes
3 answers

C: Last Bytes of UDP packets lost

I am writing an UDP-based streaming server and encountered a strange problem, I am sure it's just a simple error, but I cannot find a solution. The server does something along the lines of: FILE* infile = fopen(inf, "rb"); register int sock =…
hellerve
  • 508
  • 1
  • 6
  • 30
0
votes
1 answer

UDP message size difference

Say that A sends B a UDP message of size N like sockaddr_in to; to.sin_family=AF_INET; to.sin_port=htons(port); to.sin_addr.s_addr=inet_addr(address); sendto(sock,(const char*)buffer,N,0,(sockaddr*)&to,sizeof(to)); Now B receives this message…
user877329
  • 6,717
  • 8
  • 46
  • 88
0
votes
0 answers

how to set packet size in recvfrom

How do I set the packet size when using recvfrom()? I am trying to capture tcp packets using a Raspberry Pi Model B. I have a python program that uses recvfrom to capture the packets and write them to a .dat file. To be compatible with the matlab…
0
votes
1 answer

C recv function behavior

This is my two pieces of code: server.c #include #include #include #include #include #include #include #include #include #define BYTES_NR…
keyz
  • 55
  • 5
0
votes
1 answer

Accessing values from recvfrom() buffer

I am having a problem with the following. In particular, I am trying to extract a uint32_t and a char* from the buffer argument passed into the recvfrom() method. At this point, the integer can be extracted properly using the following…
Justin
  • 742
  • 5
  • 17
  • 34
0
votes
0 answers

c++ udp 10038 socket error on sendto()

I'm getting a 10038 socket error on a sendto() call. What could be causing this? I'm not getting any errors upon socket creation or binding. Here's how I set up my socket: Client client; client.client_socket = client.open_port(PEER_PORT2);…
stevetronix
  • 1,231
  • 2
  • 16
  • 32
0
votes
2 answers

Wait X seconds to recieve a UDP packet Python

I'm doing a client in Python, who registers into a server. That client sends a UDP packet to register and waits for a register accepted response packet from server. There's the possibility that some packets are lost, because it's UDP, so I need code…
rul3s
  • 332
  • 1
  • 2
  • 18
0
votes
1 answer

recvfrom re-reading data on socket

I'm creating a simple server/client UDP socket program and I've run into a problem. The problem is that the recvfrom() function keeps on re-reading the last data that was sent. So if I send two packets from the client to the server then recvfrom()…
user3255596
0
votes
0 answers

recvfrom returning error when trying to read UDP datagrams

I'm trying to make a very simple UDP server but I can't seem to grasp how to do it. I've looked at the Microsoft documentation but even then I ran into this problem. It seems the recvfrom function is returning an error and calling WSAGetLastError…
jocamar
  • 83
  • 9
0
votes
2 answers

Different behavior about port number between CentOS and Windows

I’ve made C programs they are the server and the client. They send message each other by using udp. The server waits until message is sent from the client. When I type some message from the client console, the client will send the message to the…
user1345414
  • 3,745
  • 9
  • 36
  • 56
0
votes
1 answer

recv() and recvfrom() methods for TCP

Why does TCP socket.recvfrom() not return the sender address as it does with UDP? When does TCP socket.recv() an empty string? Thanks!
user3109117
  • 11
  • 1
  • 4
0
votes
1 answer

C++: Classic communication exercise between server and client

Good day. As a computer science student, learning low-level C programming, i'm stucked in the "classic" practice exercise of writting a server-client communicating program. The goal is to develop a server component which receives a command from a…
JAguirre
  • 45
  • 8
1 2 3
8
9