1 /** 2 TCP stream peer. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.streampeertcp; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.streampeer; 25 import godot.reference; 26 /** 27 TCP stream peer. 28 29 This object can be used to connect to TCP servers, or also is returned by a TCP server. 30 */ 31 @GodotBaseClass struct StreamPeerTCP 32 { 33 package(godot) enum string _GODOT_internal_name = "StreamPeerTCP"; 34 public: 35 @nogc nothrow: 36 union { /** */ godot_object _godot_object; /** */ StreamPeer _GODOT_base; } 37 alias _GODOT_base this; 38 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 39 package(godot) __gshared bool _classBindingInitialized = false; 40 package(godot) static struct GDNativeClassBinding 41 { 42 __gshared: 43 @GodotName("connect_to_host") GodotMethod!(GodotError, String, long) connectToHost; 44 @GodotName("disconnect_from_host") GodotMethod!(void) disconnectFromHost; 45 @GodotName("get_connected_host") GodotMethod!(String) getConnectedHost; 46 @GodotName("get_connected_port") GodotMethod!(long) getConnectedPort; 47 @GodotName("get_status") GodotMethod!(StreamPeerTCP.Status) getStatus; 48 @GodotName("is_connected_to_host") GodotMethod!(bool) isConnectedToHost; 49 @GodotName("set_no_delay") GodotMethod!(void, bool) setNoDelay; 50 } 51 /// 52 pragma(inline, true) bool opEquals(in StreamPeerTCP other) const 53 { return _godot_object.ptr is other._godot_object.ptr; } 54 /// 55 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 56 { _godot_object.ptr = n; return null; } 57 /// 58 pragma(inline, true) bool opEquals(typeof(null) n) const 59 { return _godot_object.ptr is n; } 60 /// 61 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 62 mixin baseCasts; 63 /// Construct a new instance of StreamPeerTCP. 64 /// Note: use `memnew!StreamPeerTCP` instead. 65 static StreamPeerTCP _new() 66 { 67 static godot_class_constructor constructor; 68 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("StreamPeerTCP"); 69 if(constructor is null) return typeof(this).init; 70 return cast(StreamPeerTCP)(constructor()); 71 } 72 @disable new(size_t s); 73 /// 74 enum Status : int 75 { 76 /** 77 The initial status of the $(D StreamPeerTCP). This is also the status after disconnecting. 78 */ 79 statusNone = 0, 80 /** 81 A status representing a $(D StreamPeerTCP) that is connecting to a host. 82 */ 83 statusConnecting = 1, 84 /** 85 A status representing a $(D StreamPeerTCP) that is connected to a host. 86 */ 87 statusConnected = 2, 88 /** 89 A status representing a $(D StreamPeerTCP) in error state. 90 */ 91 statusError = 3, 92 } 93 /// 94 enum Constants : int 95 { 96 statusNone = 0, 97 statusConnecting = 1, 98 statusConnected = 2, 99 statusError = 3, 100 } 101 /** 102 Connects to the specified `host:port` pair. A hostname will be resolved if valid. Returns $(D constant OK) on success or $(D constant FAILED) on failure. 103 */ 104 GodotError connectToHost(in String host, in long port) 105 { 106 checkClassBinding!(typeof(this))(); 107 return ptrcall!(GodotError)(GDNativeClassBinding.connectToHost, _godot_object, host, port); 108 } 109 /** 110 Disconnects from host. 111 */ 112 void disconnectFromHost() 113 { 114 checkClassBinding!(typeof(this))(); 115 ptrcall!(void)(GDNativeClassBinding.disconnectFromHost, _godot_object); 116 } 117 /** 118 Returns the IP of this peer. 119 */ 120 String getConnectedHost() const 121 { 122 checkClassBinding!(typeof(this))(); 123 return ptrcall!(String)(GDNativeClassBinding.getConnectedHost, _godot_object); 124 } 125 /** 126 Returns the port of this peer. 127 */ 128 long getConnectedPort() const 129 { 130 checkClassBinding!(typeof(this))(); 131 return ptrcall!(long)(GDNativeClassBinding.getConnectedPort, _godot_object); 132 } 133 /** 134 Returns the status of the connection, see $(D status). 135 */ 136 StreamPeerTCP.Status getStatus() 137 { 138 checkClassBinding!(typeof(this))(); 139 return ptrcall!(StreamPeerTCP.Status)(GDNativeClassBinding.getStatus, _godot_object); 140 } 141 /** 142 Returns `true` if this peer is currently connected or is connecting to a host, `false` otherwise. 143 */ 144 bool isConnectedToHost() const 145 { 146 checkClassBinding!(typeof(this))(); 147 return ptrcall!(bool)(GDNativeClassBinding.isConnectedToHost, _godot_object); 148 } 149 /** 150 If `enabled` is `true`, packets will be sent immediately. If `enabled` is `false` (the default), packet transfers will be delayed and combined using $(D url=https://en.wikipedia.org/wiki/Nagle%27s_algorithm)Nagle's algorithm$(D /url). 151 $(B Note:) It's recommended to leave this disabled for applications that send large packets or need to transfer a lot of data, as enabling this can decrease the total available bandwidth. 152 */ 153 void setNoDelay(in bool enabled) 154 { 155 checkClassBinding!(typeof(this))(); 156 ptrcall!(void)(GDNativeClassBinding.setNoDelay, _godot_object, enabled); 157 } 158 }