1 /**
2 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.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.reference;
24 import godot.streampeertcp;
25 /**
26 TCP Server.
27 
28 TCP Server class. Listens to connections on a port and returns a $(D StreamPeerTCP) when got a connection.
29 */
30 @GodotBaseClass struct TCP_Server
31 {
32 	enum string _GODOT_internal_name = "TCP_Server";
33 public:
34 @nogc nothrow:
35 	union { godot_object _godot_object; Reference _GODOT_base; }
36 	alias _GODOT_base this;
37 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
38 	package(godot) __gshared bool _classBindingInitialized = false;
39 	package(godot) static struct _classBinding
40 	{
41 		__gshared:
42 		@GodotName("listen") GodotMethod!(GodotError, long, String) listen;
43 		@GodotName("is_connection_available") GodotMethod!(bool) isConnectionAvailable;
44 		@GodotName("take_connection") GodotMethod!(StreamPeerTCP) takeConnection;
45 		@GodotName("stop") GodotMethod!(void) stop;
46 	}
47 	bool opEquals(in TCP_Server other) const { return _godot_object.ptr is other._godot_object.ptr; }
48 	TCP_Server opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
49 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
50 	mixin baseCasts;
51 	static TCP_Server _new()
52 	{
53 		static godot_class_constructor constructor;
54 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("TCP_Server");
55 		if(constructor is null) return typeof(this).init;
56 		return cast(TCP_Server)(constructor());
57 	}
58 	@disable new(size_t s);
59 	/**
60 	Listen on the "port" binding to "bind_address".
61 	If "bind_address" is set as "*" (default), the server will listen on all available addresses (both IPv4 and IPv6).
62 	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.
63 	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).
64 	*/
65 	GodotError listen(StringArg1)(in long port, in StringArg1 bind_address = "*")
66 	{
67 		checkClassBinding!(typeof(this))();
68 		return ptrcall!(GodotError)(_classBinding.listen, _godot_object, port, bind_address);
69 	}
70 	/**
71 	Return true if a connection is available for taking.
72 	*/
73 	bool isConnectionAvailable() const
74 	{
75 		checkClassBinding!(typeof(this))();
76 		return ptrcall!(bool)(_classBinding.isConnectionAvailable, _godot_object);
77 	}
78 	/**
79 	If a connection is available, return a StreamPeerTCP with the connection/
80 	*/
81 	Ref!StreamPeerTCP takeConnection()
82 	{
83 		checkClassBinding!(typeof(this))();
84 		return ptrcall!(StreamPeerTCP)(_classBinding.takeConnection, _godot_object);
85 	}
86 	/**
87 	Stop listening.
88 	*/
89 	void stop()
90 	{
91 		checkClassBinding!(typeof(this))();
92 		ptrcall!(void)(_classBinding.stop, _godot_object);
93 	}
94 }