Add optional IP type param in TCP/UDP connect/set_send_address

This commit is contained in:
Fabio Alessandrelli 2016-10-28 20:35:31 +02:00
parent 812908e236
commit 2f1c859272
4 changed files with 24 additions and 5 deletions

View file

@ -38,13 +38,13 @@ String PacketPeerUDP::_get_packet_ip() const {
return get_packet_address();
}
Error PacketPeerUDP::_set_send_address(const String& p_address,int p_port) {
Error PacketPeerUDP::_set_send_address(const String& p_address,int p_port,IP_Address::AddrType p_type) {
IP_Address ip;
if (p_address.is_valid_ip_address()) {
ip=p_address;
} else {
ip=IP::get_singleton()->resolve_hostname(p_address);
ip=IP::get_singleton()->resolve_hostname(p_address, p_type);
if (ip==IP_Address())
return ERR_CANT_RESOLVE;
}
@ -62,7 +62,7 @@ void PacketPeerUDP::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_packet_ip"),&PacketPeerUDP::_get_packet_ip);
//ObjectTypeDB::bind_method(_MD("get_packet_address"),&PacketPeerUDP::_get_packet_address);
ObjectTypeDB::bind_method(_MD("get_packet_port"),&PacketPeerUDP::get_packet_port);
ObjectTypeDB::bind_method(_MD("set_send_address","host","port"),&PacketPeerUDP::_set_send_address);
ObjectTypeDB::bind_method(_MD("set_send_address","host","port","ip_type"),&PacketPeerUDP::_set_send_address,DEFVAL(IP_Address::TYPE_ANY));
}

View file

@ -42,7 +42,7 @@ protected:
String _get_packet_ip() const;
virtual Error _set_send_address(const String& p_address,int p_port);
virtual Error _set_send_address(const String& p_address,int p_port, IP_Address::AddrType p_address_type = IP_Address::TYPE_ANY);
public:

View file

@ -30,9 +30,26 @@
StreamPeerTCP* (*StreamPeerTCP::_create)()=NULL;
VARIANT_ENUM_CAST(IP_Address::AddrType);
Error StreamPeerTCP::_connect(const String& p_address,int p_port,IP_Address::AddrType p_type) {
IP_Address ip;
if (p_address.is_valid_ip_address()) {
ip=p_address;
} else {
ip=IP::get_singleton()->resolve_hostname(p_address, p_type);
if (ip==IP_Address())
return ERR_CANT_RESOLVE;
}
connect(ip,p_port);
return OK;
}
void StreamPeerTCP::_bind_methods() {
ObjectTypeDB::bind_method(_MD("connect","host","port"),&StreamPeerTCP::connect);
ObjectTypeDB::bind_method(_MD("connect","host","port","ip_type"),&StreamPeerTCP::_connect,DEFVAL(IP_Address::TYPE_ANY));
ObjectTypeDB::bind_method(_MD("is_connected"),&StreamPeerTCP::is_connected);
ObjectTypeDB::bind_method(_MD("get_status"),&StreamPeerTCP::get_status);
ObjectTypeDB::bind_method(_MD("get_connected_host"),&StreamPeerTCP::get_connected_host);

View file

@ -32,6 +32,7 @@
#include "stream_peer.h"
#include "ip_address.h"
#include "io/ip.h"
class StreamPeerTCP : public StreamPeer {
@ -50,6 +51,7 @@ public:
protected:
virtual Error _connect(const String& p_address, int p_port, IP_Address::AddrType p_type = IP_Address::TYPE_ANY);
static StreamPeerTCP* (*_create)();
static void _bind_methods();