mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 10:11:57 +03:00
Docs: Port Code Examples to C# (M, N, O, P, R)
Includes: * MarginContainer * NavigationPolygon * Node * NodePath * OS * PackedByteArray * PackedScene * PacketPeerUDP * PCKPacker * Performance * PhysicsShapeQueryParameters2D * PhysicsShapeQueryParameters3D * PrimitiveMesh * ProjectSettings Co-authored-by: Aaron Franke <arnfranke@yahoo.com>
This commit is contained in:
@@ -124,17 +124,36 @@
|
||||
<description>
|
||||
Waits for a packet to arrive on the listening port. See [method listen].
|
||||
[b]Note:[/b] [method wait] can't be interrupted once it has been called. This can be worked around by allowing the other party to send a specific "death pill" packet like this:
|
||||
[codeblock]
|
||||
# Server
|
||||
socket.set_dest_address("127.0.0.1", 789)
|
||||
socket.put_packet("Time to stop".to_ascii())
|
||||
[codeblocks]
|
||||
[gdscript]
|
||||
socket = PacketPeerUDP.new()
|
||||
# Server
|
||||
socket.set_dest_address("127.0.0.1", 789)
|
||||
socket.put_packet("Time to stop".to_ascii())
|
||||
|
||||
# Client
|
||||
while socket.wait() == OK:
|
||||
var data = socket.get_packet().get_string_from_ascii()
|
||||
if data == "Time to stop":
|
||||
return
|
||||
[/codeblock]
|
||||
# Client
|
||||
while socket.wait() == OK:
|
||||
var data = socket.get_packet().get_string_from_ascii()
|
||||
if data == "Time to stop":
|
||||
return
|
||||
[/gdscript]
|
||||
[csharp]
|
||||
var socket = new PacketPeerUDP();
|
||||
// Server
|
||||
socket.SetDestAddress("127.0.0.1", 789);
|
||||
socket.PutPacket("Time To Stop".ToAscii());
|
||||
|
||||
// Client
|
||||
while (socket.Wait() == OK)
|
||||
{
|
||||
string data = socket.GetPacket().GetStringFromASCII();
|
||||
if (data == "Time to stop")
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
[/csharp]
|
||||
[/codeblocks]
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
|
||||
Reference in New Issue
Block a user