[PHP+Python/(PortableServers)] Example #00

Post Python examples to help other users.
User avatar
Sam
Member
Posts: 73
Joined: Tue Jul 03, 2018 3:00 pm
Location: Russian Federation
Contact:

[PHP+Python/(PortableServers)] Example #00

Postby Sam » Wed Jan 29, 2020 4:35 am

Code: Select all


<?php

function microtime_float
()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}

$src = 'Hello, World!';

$t = microtime_float();
$fp = stream_socket_client("udp://127.0.0.1:885", $errno, $errstr, 30);
if (!$fp) {
    print("$errstr ($errno)\n");
}
 else {
    fwrite($fp, $src);
    while (!feof($fp)) {
        $res = fgets($fp, 512);
    }
    fclose($fp);
}
print(
'Speed: '.(microtime_float() - $t)."\r\n");
print(
'Result: '.$res."\r\n");

?>

Speed: 0.0083029270172119
Result: HELLO, WORLD!

Code: Select all


from PortableServers import SocketServerUDP

class UDPCGI
(SocketServerUDP):
    def handle(self):
        data = self.request[0].strip()
        socket = self.request[1]
        socket.sendto(data.upper(), self.client_address)

sv = UDPCGI(('127.0.0.1', 885))
sv.start()

from time import sleep
while True
:
    print('Ref!')
    sleep(5)


One example of a package... viewtopic.php?f=38&t=2175
It's a trap!

Return to “Code examples / Cookbook”

Who is online

Users browsing this forum: No registered users and 0 guests