I want to use slanger in my rails app (in my php-App it works great), but I don't get any connection.
192.168.56.101 is my local Slanger-Server, I started it with :
slanger -k 123 -s 123 -w 192.168.56.101:8080
My config/initializers/pusher.rb
Pusher.url = "192.168.56.101"
Pusher.port = 4657
Pusher.app_id = 123
Pusher.key = 123
Pusher.secret = 123
My client-script looks like this:
<script type="text/javascript">
Pusher.host = '192.168.56.101'
Pusher.ws_port = 8080
Pusher.wss_port = 8080
var pusher = new Pusher('123');
var channel = pusher.subscribe('test');
channel.bind('my_event', function(data) {
alert( data.message );
});
Pusher.log = function(data) {
console.log('\t\t', data);
};
</script>
In my firebug-console I got this:
Pusher : State changed : initialized -> connecting
Pusher : Connecting : ws://192.168.56.101:8080/app/123?protocol=5&client=js&version=1.12.5&flash=false
Firefox kann keine Verbindung zu dem Server unter ws://192.168.56.101:8080/app/123?protocol=5&client=js&version=1.12.5&flash=false aufbauen.
Pusher : Connecting : wss://192.168.56.101:8080/app/123?protocol=5&client=js&version=1.12.5&flash=false
Firefox kann keine Verbindung zu dem Server unter wss://192.168.56.101:8080/app/123?protocol=5&client=js&version=1.12.5&flash=false aufbauen.
Pusher : Error : {"type":"WebSocketError","error":{"isTrusted":true}}
Pusher : State changed : connecting -> unavailable
It was an iptables issue. shame over me
Related
Can anyone help me how to implement below using jerseyclient 1.18,this is most probably related to virtual host.
curl -k -H 'Host:b' https://a
Generally i just know how to connect one ip using code like below
Client client = Client.create();
WebResource webResource2 = client.resource("https://a");
ClientResponse response2 = webResource2.accept("application/json").header("user-agent", "").get(ClientResponse.class);
if (response2.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + response2.getStatus());
}
String output2 = response2.getEntity(String.class);
System.out.println("\n============Response============");
System.out.println(output2);
I did the migration, from Parse to Heroku and everything went smooth. At this point I didn't have any cloud code or push notifications set up on Parse. When I was done with the migration I begin to implement cloud code to handle push notification every time I save a new text message, but the Parse.Cloud.afterSave method is not running. I know main.js is working because if I implement
Parse.Cloud.define('hello', function(req, res) {
res.success('Hi');
});
I get "Hi" return to my console in Xcode, but for some reason Parse.Cloud.afterSave does nothing. I also know my Parse.Cloud.afterSave code is correct because it's that same code I use on another app through parse though. What am I missing?
Here in my index.js file
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || '',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || '',
masterKey: process.env.MASTER_KEY || '',
fileKey: 'XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', // file key from parse
serverURL: process.env.SERVER_URL || '',
push: {
ios: {
pfx: '/Users/alexcruz/Desktop/Certificates.p12', // The filename of private key and certificate in PFX or PKCS12 format from disk
bundleId: 'com.daps.DapsPush', // The bundle identifier associate with your app
production: false // Specifies which environment to connect to: Production (if true) or Sandbox
}
}
});
var app = express();
// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('Make sure to star the parse-server repo on GitHub!');
});
// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
res.sendFile(path.join(__dirname, '/public/test.html'));
});
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);
Here is my main.js file
//Push Notification for messages that are received
Parse.Cloud.afterSave("MXTMessage", function(request) {
var messageText = request.object.get('message');
var usersReceived = request.object.get('receiver');
var currentUser = Parse.User.current();
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('user', usersReceived);
pushQuery.notEqualTo('user', currentUser);
Parse.Push.send({
where: pushQuery, // Set our Installation query
data: {
alert: "New message: " + messageText
}
}, {
success: function() {
// Push was successful
},
error: function(error) {
throw "Got an error " + error.code + " : " + error.message;
}
});
});
Thank you
As I am not allowed to comment, I'm going to have to put this in an answer, but just treat it as a comment:
Did you verify the function itself is actually never being called e.g. by adding a console.log at the beginning of the function, or could it be that push itself is not working (you can check that by sending pushes via REST API Calls)? For example, push seems to be broken in parse-server 2.2.0, I had to downgrade to 1.6.0 to get it working.
Workaround could be to create a cloud code function for sending the push and have this function explicitly called by the clients after the message has been saved on the server.
Also you should check this: https://github.com/ParsePlatform/parse-server/issues/301 as you are using Parse.User.current() in your code.
Also, I get the impression that parse-server is not really stable at this time. I experience many bugs using parse-server and Heroku that the app running on parse.com does not have.
So I've gone through all of the docs on github - phpmailer xoauth tree to set up my scripts accordingly to use Google's oauth2. I am trying to send an email from the form at halcyonco.io to myself. The domain name is just to live test this site. I encounter the same error when sending the form locally.
My question is when I submit the form I receive this error:
SERVER -> CLIENT: 220 mx.google.com ESMTP pj4sm27148656pbb.29 - gsmtp
CLIENT -> SERVER: EHLO halcyonco.io
SERVER -> CLIENT: 250-mx.google.com at your service, [68.65.121.206]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
CLIENT -> SERVER: EHLO halcyonco.io
SERVER -> CLIENT: 250-mx.google.com at your service, [68.65.121.206]
250-SIZE 35882577250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH
250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING
250 SMTPUTF8
SMTP Error: Could not authenticate.
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 closing connection pj4sm27148656pbb.29 - gsmtp
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I have been in touch with Namecheap as I have my hosting and domains through them but after an hour and half they could not help me.
Below is my contact.php script
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST["user_name"]);
$email = trim($_POST["user_email"]);
$comment = trim($_POST["comment"]);
if ($name == "" OR $email == "" OR $comment == "") {
echo '<h3>Please fill out all forms.</h3>';
exit;
}
// SPAM protection
foreach ($_POST as $value) {
if ( stripos($value, 'Content-Type') !== FALSE ) {
echo "There was a problem with the information you entered.";
exit;
}
}
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('America/New_York');
require '../vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
//Load dependnecies from composer
//If this causes an error, run 'composer install'
require '../vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailerOAuth;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Set AuthType
$mail->AuthType = 'XOAUTH2';
//User Email to use for SMTP authentication - Use the same Email used in Google Developer Console
$mail->oauthUserEmail = "myemail#gmail.com";
//Obtained From Google Developer Console
$mail->oauthClientId = "1234567890.apps.googleusercontent.com";
//Obtained From Google Developer Console
$mail->oauthClientSecret = "123456789";
//Obtained By running get_oauth_token.php after setting up APP in Google Developer Console.
//Set Redirect URI in Developer Console as [https/http]://<yourdomain>/<folder>/get_oauth_token.php
// eg: http://localhost/phpmail/get_oauth_token.php
$mail->oauthRefreshToken = "1/ABCD12345EFGH6789";
//Set who the message is to be sent from
//For gmail, this generally needs to be the same as the user you logged in as
$mail->setFrom($email, $name);
//Set who the message is to be sent to
$mail->addAddress('myemail#gmail.com', 'Brandon Smith');
//Set the subject line
$mail->Subject = 'Promethean Fitness Enquiry | ' . $name;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML = $comment;
//Replace the plain text body with one created manually
$mail->Body = $comment;
$mail->AltBody = $comment;
//Attach an image file
//send the message, check for errors
if (!$mail->send()) {
echo '<h3>Please ensure you have entered a correct email address.</h3><br>';
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
header("Location: ../html/thanks.html");
exit;
}
//This is a spam protection
if ($_POST["user_address"] != "") {
echo "Your form submission has an error";
exit;
}
}
?>
Any help on what I need to do in order to fix this would be great.
I created a live chat on a rails application and I am using EventMachine to run a Websocket to have live chat. The live chat works on localhost on several machines.
It also worked on an Amazon EC2 instance in development on ubuntu, but when I tried to move it to production the live chat is no longer working. No data is being sent back and forth.
Here is my controller:
#clients = []
EM.run do
EM::WebSocket.start(host: "0.0.0.0", port: 3060) do |ws|
crypt = ActiveSupport::MessageEncryptor.new(ENV['SECRET_KEY_BASE'])
ws.onopen do |handshake|
conversation_data = crypt.decrypt_and_verify(handshake.query_string)
#clients << {socket: ws, conv_info: conversation_data}
end
ws.onclose do
ws.send "Closed."
#clients.delete ws
end
ws.onmessage do |data|
data = data.split('L56HTY9999')
body = data[0]
key = data[-1]
conversation = crypt.decrypt_and_verify(key)
new_message = Message.new(body: body, user_id: conversation[:user_id], conversation_id: conversation[:conversation_id])
if new_message.save
#clients.each do |socket|
if socket[:conv_info][:conversation_id] == conversation[:conversation_id]
socket[:socket].send new_message.chat_show
end
end
else
if socket[:conv_info][:user_id] == conversation[:user_id]
socket[:socket].send new_message.errors.to_json
end
end
end
end
end
This is my javascript on the page:
function addMessage(msg) {
var content = JSON.parse(msg);
var context = {
userImage: content.image,
author: content.username,
convoText: content.body,
time: content.created_at
};
var source = $('#add-newest-comment').html();
var template = Handlebars.compile(source);
var newComment = template(context);
$('#container').append(newComment);
}
var key = '<%= #conv_id %>';
var socket, host;
host = "ws://0.0.0.0:3060?"+ key;
function onErrors(msg){
$("#chat-log .error").text( msg);
setTimeout(function() {
$( "#chat-log .error" ).text("");
}, 3000);
}
function socketHealth(msg){
console.log(msg);
}
function connect() {
try {
socket = new WebSocket(host);
socketHealth("Socket State: " + socket.readyState);
socket.onopen = function() {
socketHealth("Socket Status: " + socket.readyState + " (open)");
}
socket.onclose = function() {
socketHealth("Socket Status: " + socket.readyState + " (closed)");
}
socket.onmessage = function(msg) {
addMessage(msg.data);
}
} catch(exception) {
onErrors("Error: " + exception);
}
}
$(function() {
connect();
});
function send() {
var text = $("#message").val();
if (text == '') {
onErrors("Please Enter a Message");
return;
}
try {
socket.send(text + 'L56HTY9999' + key);
} catch(exception) {
onErrors("Failed To Send")
}
$("#message").val('');
}
$('#message').keypress(function(event) {
if (event.keyCode == '13') { send(); }
});
$("#disconnect").click(function() {
socket.close()
});
I'm running my server with this command:
bundle exec thin start -p 80 -d -l thin.log -P thin.pid
My site is live at http://puppyplaydate.co/
The console logs this
Socket State: 0
messages:153 WebSocket connection to 'ws://0.0.0.0:3060/?aVI0OFVHS2VET3d4OTQ4M2s4Rk5VMld1eVlXOUFoVUFxT1JMSm5LWDJOUEhScU50MzFub2JMQ3Y4NG1uekl3TS0tYnlBU1ZRclErK3QxWERHN0taSTVzUT09--01ec4a49ce0aeef59bee5d5b8e13d7916abc20e1' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
messages:148 Socket Status: 3 (closed)
I used netstat to check that the server was listening at that port and got this back:
tcp 0 0 *:3060 *:* LISTEN
I researched online and someone said they used "daemon" gem to run the websocket on production? I'm not sure if that's something that I need.
I'm really stuck, thank you in advance for your help!
The issue was that I was running the Thin server and not Rails, instead of running the Rails server which was set to boot up Thin as well.
i setted up a node server, this sends data via socket.io to the clients and use that in a phonegap projekt,
it works fine when i test it in browsers & mobile browsers but it does not work when i build a ios app which i run in the emulator,
part of node server code:
define(['node-static','http'],function (Static,Http) {
return FileServer = function (server) {
var httpFileServer = new Static.Server('./phonegap/www');
Http.createServer(function (request, response) {
request.addListener('end', function () {
httpFileServer.serve(request, response);
}).resume();
}).listen(server.fileServerHTTPport,"0.0.0.0");
return {
// exampleVariable : function() {return exampleVariable},
// exampleFunction : exampleFunction
}
} });
index.html phonegap
... <script src="js/socket.io.js"></script>
<script src="js/jquery-2.0.3.min.js"></script>
<script>
var socket = io.connect('http://'+document.location.hostname+':54321');
socket.on('display', function (data) {
console.log(data.color);
$("h1").text( data.color.h );
});
</script></head>
<body><h1> hello world</h1> ...
I figured out, i have to use the devices default localhost ip,
so for example in ios: 127.0.0.1
var socket = io.connect('http://127.0.0.1:54321');