Created
January 7, 2020 16:13
-
-
Save diyism/a32decce4fd3cd831a44493c1096b047 to your computer and use it in GitHub Desktop.
udp traffic forwording with swoole udp server or swoole udp client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ch=''; | |
$udp_server=new swoole_server('0.0.0.0', 21414, SWOOLE_BASE, SWOOLE_UDP); | |
$udp_server->on('packet', function ($ipsock, $data, $ipsock_con) /* use(&$ch) */ | |
{ | |
//echo $data."=========sent====\n\n"; | |
if ($ipsock_con['port']!=21406) | |
{ | |
$ipsock->sendto('127.0.0.1', 21406, $data); //to wg | |
} | |
else | |
{ | |
$ipsock->sendto('127.0.0.2', 21409, $data); //to tws | |
} | |
} | |
); | |
/*$udp_server->on('workerstart', function($ipsock, $worker_id) | |
{ | |
if ($worker_id==0) | |
{ | |
$ch=new swoole_client(SWOOLE_UDP | SWOOLE_ASYNC); | |
$ch->set(array('bind_address'=>'127.0.0.1', 'bind_port'=>21414)); | |
$ch->on('receive', function ($ch, $data) | |
{ | |
$src_ip_port=$ch->getPeerName(); | |
//echo $data.$src_ip_port['port']."==========received===\n\n"; | |
if ($src_ip_port['port']!=21406) | |
{ | |
$ch->sendto('127.0.0.1', 21406, $data); //to wg | |
} | |
else | |
{ | |
$ch->sendto('127.0.0.2', 21409, $data); //to tws | |
} | |
} | |
); | |
$ch->on('connect', function($ch){}); //don't remove this line | |
$ch->connect('127.0.0.2', 21409, 0.3); | |
} | |
} | |
);*/ | |
$udp_server->start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment