Download .zip |
Info | Documentation | View files (55) | Download .zip | Reputation | Support forum (1) | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2019-05-12 (16 hours ago) | Not yet rated by the users | Total: 137 This week: 7 | All time: 8,825 This week: 48 |
Version | License | PHP version | Categories | |||
stream7 1.0.6 | MIT/X Consortium ... | 5 | Networking, PHP 5, Stream wrappers, PSR |
Description | Author | |
This package is PSR 7 based network connection client and server. |
__Server__
ob_end_clean();
header("Connection: keep-alive");
ignore_user_abort(); // optional
ob_start();
echo ('Server Listening ....');
ob_end_flush(); // Strange behaviour, will not work
flush();
$connect = function()
{
// Create TCP Server And Bind On Port #8000
$socket = new StreamServer('tcp://0.0.0.0:8000');
$socket->bind();
return $socket;
};
/ @var StreamServer $socketServer */
$socketServer = $connect();
while (1)
{
try {
// Listen On Port Till Client Connect ...
$streamable = $socketServer->listen();
} catch (TimeoutException $e) {
// If Connection Timeout Connect Again, and listen
$socketServer->shutdown(); // free server port
$socketServer = $connect(); // connect again ..
continue;
}
ob_start();
echo '<br/><br/>'."Client Connected: "
.(
$streamable->getResource()
->getRemoteName()
);
ob_end_flush();flush();
// While Client Not Closed Connection ...
$response = '';
while ($streamable->getResource()->isAlive())
{
$clientMessage = $streamable->readLine();
ob_start();
switch ($clientMessage) {
case 'bye':
echo '<br/>'."> bye "
.(
$streamable->getResource()
->getRemoteName()
);
// send back response
$streamable->write($response);
// close client connection
$streamable->getResource()->close();
break;
case 'time':
echo '<br/> >'.$clientMessage;
$response .= date("D M j H:i:s Y\r\n");
break;
default:
echo '<br/>'.'>'.$clientMessage. ', Not Recognized.';
}
ob_end_flush();flush();
}
}
__Client__
$socks = new StreamClient('tcp://127.0.0.1:8000');
try {
$resrc = $socks->getConnect();
} catch (\Exception $e) {
throw new \Exception('Not Connected.', null, $e);
}
$clientStream = new Streamable($resrc);
echo $clientStream->getResource()->getLocalName();
$clientStream->sendData("time\n");
$clientStream->sendData("not known command\n");
$clientStream->sendData("bye\n");
// Get Back Response
echo $clientStream->read();
Files |
File | Role | Description | ||
---|---|---|---|---|
Context (6 files, 1 directory) | ||||
Exception (1 file) | ||||
Filter (4 files) | ||||
fixes (1 file) | ||||
Interfaces (6 files, 4 directories) | ||||
Psr (2 files) | ||||
Resource (2 files) | ||||
Streamable (7 files, 1 directory) | ||||
Wrapper (4 files, 2 directories) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation | ||
ResourceStream.php | Class | Class source | ||
Streamable.php | Class | Class source | ||
StreamClient.php | Class | Class source | ||
StreamServer.php | Class | Class source | ||
StreamWrapperClient.php | Class | Class source |
Files | / | Context |
File | Role | Description | ||
---|---|---|---|---|
fixes (1 file) | ||||
aContextStream.fix.php | Class | Class source | ||
aContextStream.php | Aux. | Auxiliary script | ||
ContextStreamBase.php | Class | Class source | ||
ContextStreamHttp.php | Class | Class source | ||
ContextStreamSocket.php | Class | Class source | ||
FactoryContextStream.php | Class | Class source |
Files | / | Filter |
File | Role | Description |
---|---|---|
aFilterStreamCustom.php | Class | Class source |
FilterStreamBadword.php | Class | Class source |
FilterStreamPhpBuiltin.php | Class | Class source |
RegistryOfFilterStream.php | Class | Class source |
Files | / | Interfaces |
File | Role | Description | ||
---|---|---|---|---|
Context (1 file) | ||||
Filter (3 files) | ||||
Resource (3 files) | ||||
Wrapper (2 files) | ||||
iResourceStream.php | Class | Class source | ||
iStreamable.php | Class | Class source | ||
iStreamClient.php | Class | Class source | ||
iStreamCommon.php | Class | Class source | ||
iStreamServer.php | Class | Class source | ||
iWrapperStreamClient.php | Class | Class source |
Files | / | Interfaces | / | Filter |
File | Role | Description |
---|---|---|
iFilterStream.php | Class | Class source |
iFilterStreamCustom.php | Class | Class source |
iRegistryOfFilterStream.php | Class | Class source |
Files | / | Interfaces | / | Resource |
File | Role | Description |
---|---|---|
iAccessModeToResourceStream.php | Class | Class source |
iBuilderOfResourceStream.php | Class | Class source |
iMetaReaderOfPhpResource.php | Class | Class source |
Files | / | Interfaces | / | Wrapper |
File | Role | Description |
---|---|---|
iRegistryOfWrapperStream.php | Class | Class source |
iWrapperStream.php | Class | Class source |
Files | / | Psr |
File | Role | Description |
---|---|---|
StreamBridgeFromPsr.php | Class | Class source |
StreamBridgeInPsr.php | Class | Class source |
Files | / | Resource |
File | Role | Description |
---|---|---|
AccessMode.php | Class | Class source |
MetaReaderOfPhpResource.php | Class | Class source |
Files | / | Streamable |
File | Role | Description | ||
---|---|---|---|---|
AggregateStreams (1 file) | ||||
.todo.php | Aux. | Auxiliary script | ||
SAggregateStreams.php | Class | Class source | ||
SDecorateStreamable.php | Class | Class source | ||
SLimitSegment.php | Class | Class source | ||
STemporary.php | Class | Class source | ||
SUpstream.php | Class | Class source | ||
tDecorateStreamable.php | Class | Class source |
Files | / | Streamable | / | AggregateStreams |
File | Role | Description |
---|---|---|
ResourceAggregate.php | Class | Class source |
Files | / | Wrapper |
File | Role | Description | ||
---|---|---|---|---|
FileAccessControl (2 files) | ||||
PsrToPhpResource (1 file) | ||||
aWrapperStream.php | Class | Class source | ||
RegistryOfWrapperStream.php | Class | Class source | ||
WrapperFileAccessControl.php | Class | Class source | ||
WrapperPsrToPhpResource.php | Class | Class source |
Files | / | Wrapper | / | FileAccessControl |
File | Role | Description |
---|---|---|
ACWOptions.php | Class | Class source |
ACWPermissions.php | Class | Class source |
Files | / | Wrapper | / | PsrToPhpResource |
File | Role | Description |
---|---|---|
OptsPsrToPhpResource.php | Class | Class source |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.