mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
cleanup
This commit is contained in:
parent
29d97125f0
commit
677136ca5d
2 changed files with 7 additions and 13 deletions
|
|
@ -1,26 +1,26 @@
|
|||
for i = 1, 3 do
|
||||
debug.log(string.format("iteration %s", i))
|
||||
print(string.format("iteration %s", i))
|
||||
local complete = false
|
||||
|
||||
local server = network.udp_open(8645 + i, function (address, port, data, srv)
|
||||
debug.log(string.format("server received %s byte(s) from %s:%s", #data, address, port))
|
||||
print(string.format("server received %s byte(s) from %s:%s", #data, address, port))
|
||||
srv:send(address, port, "pong")
|
||||
end)
|
||||
|
||||
network.udp_connect("localhost", 8645 + i, function (data)
|
||||
debug.log(string.format("client received %s byte(s) from server", #data))
|
||||
print(string.format("client received %s byte(s) from server", #data))
|
||||
complete = true
|
||||
end, function (socket)
|
||||
debug.log("udp socket opened")
|
||||
print("udp socket opened")
|
||||
start_coroutine(function()
|
||||
debug.log("udp data-sender started")
|
||||
print("udp data-sender started")
|
||||
for k = 1, 5 do
|
||||
local payload = ""
|
||||
for j = 1, 16 do
|
||||
payload = payload .. math.random(0, 9)
|
||||
end
|
||||
socket:send(payload)
|
||||
debug.log(string.format("sent packet %s (%s bytes)", k, #payload))
|
||||
print(string.format("sent packet %s (%s bytes)", k, #payload))
|
||||
coroutine.yield()
|
||||
end
|
||||
socket:close()
|
||||
|
|
|
|||
|
|
@ -804,17 +804,11 @@ public:
|
|||
}
|
||||
|
||||
void sendTo(const std::string& addr, int port, const char* buffer, size_t length) override {
|
||||
logger.info() << "sendto " << addr << ":" << port;
|
||||
sockaddr_in client{};
|
||||
client.sin_family = AF_INET;
|
||||
inet_pton(AF_INET, addr.c_str(), &client.sin_addr);
|
||||
client.sin_port = htons(port);
|
||||
|
||||
sockaddr_in client = resolve_address_dgram(addr, port);
|
||||
if (sendto(descriptor, buffer, length, 0,
|
||||
reinterpret_cast<sockaddr*>(&client), sizeof(client)) < 0) {
|
||||
logger.error() << handle_socket_error("sendto").what();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void close() override {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue