Ratchet WAMP $topic error:Call to a member function broadcast() on a non-object - wamp

The title says it all.Here's my code:
(Shell script)
$loop = React\EventLoop\Factory::create();
$pusher = new MyApp\Chat;
//Receiving IPC messages:
$socket = new React\Socket\Server($loop);
$socket->on('connection', function ($conn) {
$pusher = new MyApp\Chat;
echo date('H:i:s'). "!!IPC Connection opened!!\n";
$conn->on('data', array($pusher, 'onUpdate'));
});
$socket->listen(1337, '127.0.0.1'); //Binding to our IP so remotes can't connect.
echo "%%% IPC listener started succesfully. %%%\n%%%\n";
// WebSocket server:
//here the code is identical to that on the Ratchet 'push-server' tutorial
...and the "onUpdate" function...
public function onUpdate($entry)
{
echo(date('H:i:s'). ": !<<---IPC Data Received.DATA:::". $entry. ":::--->>!\n");
$topic = 'Prime_mover';
$topic->broadcast($entry);
}
...the "onPublish" function:
public function onPublish(Conn $conn, $topic, $event, array $exclude, array $eligible )
{
echo $topic. "\n";
//echo implode(array_keys($topic)). "\n";
$channel = $topic->getId();
if($topic->broadcast($event))
{
echo(date('H:i:s') . ": ***A client has published ###" .
implode('', $event) . "### to (((". $channel. ")))***\n");
} else {
echo(date('H:i:s'). ": !!<--An error occured during publish-->!!\n");
}
}
The client code is trivial.
I am sure the bug, if any (I've been at this for about 10 hours), does not reside there.
I confirm via the console that indeed the browser is subscribed to "Prime_mover". This also shows up on the CLI. In addition, I have put a button that publishes to this channel, via the "onPublish" function. This works.
As can be seen above, I am not using ZeroiMQ for IPC because I am developing on a windows machine, on PHP 5. AFAIK, there exists no working ZeroMQ bindings for PHP5.
I resorted to using bare sockets. They work just as beautifully, and I can see on the CLI that the messages do get to this particular script.
The "onUpdate" function does get called, confirmed, again, via the CLI.
I had previously tried using the URL "http:\example.com\Prime_mover", when it did not work, out of desperation, I tried the string "Prime_mover". You're probably shaking your head right now-I know, does't work that way.
I have tried to use $topica as an array too, does not work.I guess the most important question here is, what kind of object is $topic, why won't a simple string work in it's place?Am I missing something here?How is it "constructed" correctly?

$topic = 'Prime_mover';
$topic->broadcast($entry);
$topic is a string! And it doesn't have any methods.

Related

Execute /bin/login from QProcess

I'm working on embedded system running linux (without X11 server). I want my Qt application to be started with root privileges then from within spawn new QProcess which should be "/bin/login user_name" then provide password.
The problem is the "Password:" that usually prints on console (I assume it's stdout) doesn't show up, and QProcess.write() doesn't seem to work at all. If I run this QProcess as normal user I get an error message at redirected stderr (via setStandardErrorFile). I think I have general problem with understanding /bin/login.
I tried to
echo "userPassword" > /proc/LOGIN_PID/fd/0
from different console, but it also doesn't work.
The function I wrote in c++ goes like this:
void BashWrapper::bashEcho(QStringList t_echo){
QString bash = "/bin/login";
QStringList args(t_echo[0]);
static QProcess *newProc = new QProcess();
newProc->setStandardOutputFile("/dev/pts/2");
newProc->setStandardErrorFile("/dev/pts/2");
newProc->start(bash,args);
if(newProc->waitForStarted()){
qDebug() << newProc->state();
}
newProc->write(t_echo[1].toUtf8());
if(!newProc->waitForFinished(10000)){
qDebug() << "timeout";
}
else{
qDebug() << "finished";
}
}
t_echo contains ("user_name", "userPassword")
What I want to do is spawn new program (let's say /bin/myApp) as user_name. I thought that login as that user and setting .bash_profile to run /bin/myApp would be easy, painless and... secure?
If using /bin/login from application is impossible is there any simple way to this?
Best Regards,
MichaƂ
Ok, I found the answer here:
https://www.thegeekstuff.com/2010/10/expect-examples/ There is an example script that executes su command, simply changing it to /bin/login allowed me to pass the password via some addtional scripts.

PhpUnit unable to access external url

On my local windows PC I am running XAMPP and it is serving a testpage on it (e.g. http://localhost/testsite/testpage.html)
Now on the same machine I have an instance of laravel 5.2 running and I have one named route in it called testroute.
I write a phpunit test cases
public function testBasicExample1() {
$this->visit('testroute')->see('Something'); //Passes
}
public function testBasicExample2() {
$this->visit('http://www.google.com')->see('Google'); //Passes
}
public function testBasicExample3() {
$this->visit('http://localhost/testsite/testpage.html')->see('Something Else');
//Fails as it is unable to reach the desired page (Received status code [404])
}
in TestCase.php
$baseUrl = 'http://localhost:8000';
and in .env APP_URL=http://localhost:8000
Is it know that localhost sites cannot be accessed in phpunit?
Update:
I figured out even http://www.google.com is not working, it is redirecting to the laravel's welcome route. (test passed as there was text 'Google' in that page as well). Basically it was trying to assess http://localhost:8000/www.google.com and that redirects to welcome page.
I am not sure how in laravel's phpunit I can access external url.
I banged my head against a wall for a long time with this. I don't believe it is possible / functional to test external sites with the Laravel click() or visit() methods. If it is, I'm not seeing it.
Though my need was to just check all my links, perhaps this hack may be helpful to you. I went back to basic php to assert the sites returned properly.
$sites = \App\Website::pluck('website');
foreach($sites as $site) {
$file_headers = #get_headers($site);
if (strpos($file_headers[0], '404 Not Found') || $file_headers[0] == null) {
$exists = false;
echo " Failed on: ".$site." ";
}
else {
$exists = true;
}
$this->assertTrue($exists);
}
It doesn't quite get you all the way to what you want (seeing something), but for me it was good enough to be able to see the link was live and successful.
Testing is slow as it is going out to x # of sites.
HTH

QuickFIX Initiator can't send message

I've been trying to use QuickFIX to setup a client. It's the example from the QuickFIX site, as follows:
int main( int argc, char** argv ) {
try
{
if(argc < 2) return 1;
std::string fileName = argv[1];
FIX::SessionSettings settings(fileName);
Handler application;
FIX::FileStoreFactory storeFactory(settings);
FIX::FileLogFactory logFactory(settings);
FIX::SocketInitiator initiator(application, storeFactory, settings, logFactory /*optional*/);
initiator.start();
cout << "Started.\n";
initiator.block();
cout << "Stopped.\n";
return 0;
}
catch(FIX::ConfigError& e)
{
std::cout << e.what();
return 1;
}
}
And I defined the Handler implementing the Application class.
And the config file looks like below:
# default settings for sessions
[DEFAULT]
ConnectionType=initiator
ReconnectInterval=60
SenderCompID=CLIENT
FileLogPath=.
FileStorePath=.
DataDictionary=D:\Program Files\quickfix\spec\FIX44.xml
# session definition
[SESSION]
# inherit ConnectionType, ReconnectInterval and SenderCompID from default
BeginString=FIX.4.4
TargetCompID=SERVER
HeartBtInt=30
SocketConnectPort=6523
SocketConnectHost=127.0.0.1
StartTime=8:00:00
EndTime=23:00:00
When running, the Handler::toAdmin and Handler::onCreate got called, then the block function blocks. But using the small FIX application Mini-FIX as the server, I could not get any incoming message from the program. I have tried opening two Mini-FIX, one as a server, one as a client, and they communicate just fine. And I have made sure that the ID's and listening port are correct. So what would be the problem? Mini-FIX should have received the toAdmin Message 8=FIX.4.4|9=55|35=5|34=1|49=CLIENT|52=20120702-08:29:25.334|56=SERVER|10=115 sent by the program.
Tthe start time and endtime seems strange, but the toAdmin actually got called. So I assume the message should have already sent.
Edit
I solved the problem already after I made several changes to the config file and the program, but I am not quite sure what caused it. Consider this closed.
The FIX message you post in your question is a LOGOUT message (35=5), and it's very strange to initiate the connection with this kind of message. I expect that the first message is a LOGON (35=A). Try to reset the sequence numbers at every logon, adding this line in the config:
ResetOnLogon=Y
Also in the QuickFIX distribution there is a small server (executor) that you can use to test your client. Please find the server here:
http://www.quickfixengine.org/quickfix/doc/html/examples.html
The problem has gone, after I manipulated the config file and the Mini-FIX.
It seems that it was caused by several reasons:
The time should be set in the interval.
Mini-FIX which acts as server should set the targetcomputerid correctly.
initiator.block() is enough for starting the engine and waiting. No need to run start() and block() both.

Spring Controller Times Out with Large #PathVariable

Ok, so here's a tricky riddle I've been wrestling with today. First here is my controller:
#RequestMapping(value = "/batch/{itemIds:(?:[0-9]+[,]?)+}", method = RequestMethod.DELETE)
public void batchDeleteItem(
#PathVariable String itemIds,
Principal principal,
HttpServletResponse httpServletResponse) throws CustomException {
for (String itemIdString: itemIdString.split(",")) {
long
itemId = Long.parseLong(itemIdString.trim());
itemService.deleteItem(principal.getName(), itemId);
}
httpServletResponse.setStatus(HttpServletResponse.SC_ACCEPTED);
}
In case it's not obvious, the idea is to delete a bunch of items in one call to the controller. The above method works well for around 5 items, but when 6+ are specified the call times out. I've put logger statements in the controller code and they never even get printed! To put it another way,
WORKS:
curl -u test:pass 'http://localhost:8080/rest/item/batch/23,24,25,26,27' -X DELETE
Returns ACCEPTED
Items are deleted
TIMES OUT:
curl -u test:pass 'http://localhost:8080/rest/item/batch/23,24,25,26,27,28,29,30,31,32,33' -X DELETE
Hangs forever (or the client times out)
Items are not deleted
Any ideas? Thanks in advance!
UPDATE:
For now I'm working around the issue by having the client specify a CSV formatted body of the request (rather than in the URL itself). Unfortunately this means using HTTP PUT instead of HTTP DELETE. I'll still leave this question open if anyone can figure out what's going on.

Facebook Connect (PHP-Api) doesnt set cookie anymore on certain computers

I have a very strange issue with facebook-connect within my PHP-Webapplication. From one day to the other facebook-connect doesnt work anymore, but only on one on the computers.
This is my code that fails:
// try to get Cookie
$cookie = null;
try {
$cookie = $_COOKIE['fbs_' . $app_id];
} catch (ErrorException $ex) {
echo $ex->getMessage();
}
This is the error message i get:
'Undefined index: fbs_myAppId'
I know that it means, that facebook hasnt set the cookie, like it was supposed to! But the weired thing is, that it works properly on other computers. On the computer where it didnt work, i tried Opera, Chrome, Firefox and IE. I made sure that 3rd Party-Cookies are enabled. And I can properly log on into the normal facebook-website.
So what am I missing???
The proble was the time-setting on the computer: the time was set one month in advance. Apparently the facebook-cookies have an expire-time of one day. So it was immediatly deleted by the browser.