Sign in to follow this  
photo

recvfrom

Recommended Posts

Posted (edited)

Unigine::Socket Class

Header: #include <UnigineStreams.h>
Inherits: Stream

This class provides basic functionality for network interaction using stream sockets.

 

if I use Unigine's socket as UDP, is there a way to know the address information that sent the data? like recvefrom

Edited by dongju.jeong

Share this post


Link to post

The method recvfrom and sendto is called inside Socket::read and Socket::write if you created an UDP socket (SOCKET_DGRAM). 

  • Like 1

Share this post


Link to post
Posted (edited)

Then, if I just use send() after read() without additional work on the same socket, is the data automatically sent to the sending ip?

Edited by dongju.jeong

Share this post


Link to post

image.png

only set size of buffer

setsockopt(data->fd, SOL_SOCKET, SO_SNDBUF, (char *)&size, sizeof(size))

 

you need any of Socket::write... methots (these are inherited from UnigineStream )
image.png

 

 

  • Like 1

Share this post


Link to post
Posted (edited)

sorry.... it is my mistake.

 

I mean "Then, if I just use write() after read() without additional work on the same socket, is the data automatically sent to the sending ip?"

The point of this question is, when udp socket is created for receiving, I send the data to the sending ip through the same socket after receiving data.

like normal window socket programming.

 

image.png.c63886449d801729cc474665295700df.png

 

Edited by dongju.jeong

Share this post


Link to post

yes
this is part of source code
 

size_t Socket::read(void *ptr, size_t size) const
{
	...
	if (data->type == SOCKET_STREAM)
	{
		::recv(data->fd, (char *)ptr, (int)to_read, flags);
	} else if (data->type == SOCKET_DGRAM)
	{
		recvfrom(data->fd, (char *)ptr, (int)to_read, flags, (struct sockaddr *)&data->addr, &length);
	}
	...
	return  read / size;
}

size_t Socket::write(const void *ptr, size_t size) const
{
	...
	if (data->type == SOCKET_STREAM)
	{
		::send(data->fd, (char *)ptr, (int)to_write, flags);
	} else if (data->type == SOCKET_DGRAM)
	{
		sendto(data->fd, (char *)ptr, (int)to_write, flags, (struct sockaddr *)&data->addr, sizeof(data->addr));
	}
	...
	return write / size;
}

 

  • Like 1

Share this post


Link to post
Sign in to follow this