1 /**
2 A TCP server.
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.tcp_server;
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.reference;
25 import godot.streampeertcp;
26 /**
27 A TCP server.
28 
29 Listens to connections on a port and returns a $(D StreamPeerTCP) when it gets an incoming connection.
30 */
31 @GodotBaseClass struct TCP_Server
32 {
33 	package(godot) enum string _GODOT_internal_name = "TCP_Server";
34 public:
35 @nogc nothrow:
36 	union { /** */ godot_object _godot_object; /** */ Reference _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("is_connection_available") GodotMethod!(bool) isConnectionAvailable;
44 		@GodotName("is_listening") GodotMethod!(bool) isListening;
45 		@GodotName("listen") GodotMethod!(GodotError, long, String) listen;
46 		@GodotName("stop") GodotMethod!(void) stop;
47 		@GodotName("take_connection") GodotMethod!(StreamPeerTCP) takeConnection;
48 	}
49 	/// 
50 	pragma(inline, true) bool opEquals(in TCP_Server other) const
51 	{ return _godot_object.ptr is other._godot_object.ptr; }
52 	/// 
53 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
54 	{ _godot_object.ptr = n; return null; }
55 	/// 
56 	pragma(inline, true) bool opEquals(typeof(null) n) const
57 	{ return _godot_object.ptr is n; }
58 	/// 
59 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
60 	mixin baseCasts;
61 	/// Construct a new instance of TCP_Server.
62 	/// Note: use `memnew!TCP_Server` instead.
63 	static TCP_Server _new()
64 	{
65 		static godot_class_constructor constructor;
66 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("TCP_Server");
67 		if(constructor is null) return typeof(this).init;
68 		return cast(TCP_Server)(constructor());
69 	}
70 	@disable new(size_t s);
71 	/**
72 	Returns `true` if a connection is available for taking.
73 	*/
74 	bool isConnectionAvailable() const
75 	{
76 		checkClassBinding!(typeof(this))();
77 		return ptrcall!(bool)(GDNativeClassBinding.isConnectionAvailable, _godot_object);
78 	}
79 	/**
80 	Returns `true` if the server is currently listening for connections.
81 	*/
82 	bool isListening() const
83 	{
84 		checkClassBinding!(typeof(this))();
85 		return ptrcall!(bool)(GDNativeClassBinding.isListening, _godot_object);
86 	}
87 	/**
88 	Listen on the `port` binding to `bind_address`.
89 	If `bind_address` is set as `"*"` (default), the server will listen on all available addresses (both IPv4 and IPv6).
90 	If `bind_address` is set as `"0.0.0.0"` (for IPv4) or `"::"` (for IPv6), the server will listen on all available addresses matching that IP type.
91 	If `bind_address` is set to any valid address (e.g. `"192.168.1.101"`, `"::1"`, etc), the server will only listen on the interface with that addresses (or fail if no interface with the given address exists).
92 	*/
93 	GodotError listen(in long port, in String bind_address = gs!"*")
94 	{
95 		checkClassBinding!(typeof(this))();
96 		return ptrcall!(GodotError)(GDNativeClassBinding.listen, _godot_object, port, bind_address);
97 	}
98 	/**
99 	Stops listening.
100 	*/
101 	void stop()
102 	{
103 		checkClassBinding!(typeof(this))();
104 		ptrcall!(void)(GDNativeClassBinding.stop, _godot_object);
105 	}
106 	/**
107 	If a connection is available, returns a StreamPeerTCP with the connection.
108 	*/
109 	Ref!StreamPeerTCP takeConnection()
110 	{
111 		checkClassBinding!(typeof(this))();
112 		return ptrcall!(StreamPeerTCP)(GDNativeClassBinding.takeConnection, _godot_object);
113 	}
114 }