dongju.jeong Posted June 25, 2020 Share Posted June 25, 2020 (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 June 25, 2020 by dongju.jeong Link to comment
cash-metall Posted June 25, 2020 Share Posted June 25, 2020 The method recvfrom and sendto is called inside Socket::read and Socket::write if you created an UDP socket (SOCKET_DGRAM). 1 Link to comment
dongju.jeong Posted June 25, 2020 Author Share Posted June 25, 2020 (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 June 25, 2020 by dongju.jeong Link to comment
cash-metall Posted June 25, 2020 Share Posted June 25, 2020 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 ) 1 Link to comment
dongju.jeong Posted June 25, 2020 Author Share Posted June 25, 2020 (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. Edited June 25, 2020 by dongju.jeong Link to comment
cash-metall Posted June 25, 2020 Share Posted June 25, 2020 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; } 1 Link to comment
Recommended Posts