Unable to connect to Node server using Socket.io - ios

Im unable to connect to my Node server using Socket.io. I have been following these two tutorials http://www.appcoda.com/socket-io-chat-app/ and http://socket.io/get-started/chat/ but I cant seem to figure out where i'm going wrong. My goal is to connect my Node server to an ios app in Xcode. Here is the server file:
//require HTTP module/create server
var app = require ('http').createServer();
//Port Number
app.listen(3000)
//Run Server
var io = require('socket.io')(app);{
console.log('Listening on *:3000');
};
//Connection
io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
});
When I run the server via terminal, i get Listening on *:3000 as the output
(According to the tutorial) I then import the Socket.io Source folder and create the SocketIOManager.swift file as well as edit my AppDelegate.swift file
According to both tutorials I'm suppose to read a user connected when I open the simulator and user disconnected when i close it. However i get nothing in terminal. And i'm not sure what this means because i'm not getting any errors in Xcode.
Also when I run the server and open a browser i get the following:
I'm not sure if the browser issue relates or not but im putting it out there. Im only trying trying to connect my server to the app. I am looking forward to the a user connected message because that will verify a connection. If there is another way to test for a connection kindly let me know. Frankly, if there is a more simplified way to connect my server to the app, that would be greatly appreciated. I am open to any additional questions and of course comments.
Thank you in advance!
EDIT
I have SocketIOManager.sharedInstance.establishConnection() in my viewcontroller as is but I still cannot establish a connection. Can anyone shed some light?

Related

When using NEHotspotConfiguration() to joing a network. Always recieve "unable to join"

I am implementing an APP through Xamarin that will force the iPhone to connect to a specific SSID.
Here is my code
var config = new NEHotspotConfiguration(SSID, Password, isWep: false)
config.JoinOnce = true;
var tcs = new TaskCompletionSource<NSError>();
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(config, err => tcs.SetResult(err));
There are two test result
Assume the target SSID I want to connect called "SSID-A"
I delete the record of "SSID-A" in the iOS system page. Then deploy this APP to the phone.
I give the correct SSID/Password into the code above.
The system popup a message "Unable to join". Failed to connect to this SSID.
I go to iOS system page. Manually connect to "SSID-A". Check the connection is done.
Then I connect to mobile phone to other SSID. And go back to the APP.
This time. It works.
Why there is a different at here?
What can I do to look more into this problem to solve this?
Thanks!
From applyConfiguration:completionHandler: of apple document, we could see the dicsussion that:
This method attempts to join the network only if it's found nearby. Also, because of the noticeable delay that the Hotspot 2.0 discovery mechanism may incur, the method doesn't attempt to join Hotspot 2.0 networks.
Therefore, Join once seems can not mark sure it works.We could have a try with remove this line, or set false as follows:
config.joinOnce = false;
In addition, it seems a bug in iOS 13 from Apple. You could have a look at this discussion.
In case it helps someone one day I had an issue suddenly start where my device was unable to join a network which has previously been working fine.
To test an error condition I tried connecting to a secure network without adding the passphase to the NEHotspotConfiguration. This attempt to join failed but then subsequently after putting the passphase back in the device wouldn't even display the join request dialog and would just fail with an 'Unable to join' error.
I eventually tried another test phone and this worked just fine so it seemed to be an issue on the device itself. I tried resetting my device's network settings but this made no difference.
The fix was to go into the device's wifi setting, join the network manually, return to my app, attempt to join, disconnect from the network in the device settings, and then forget the network. After that it worked fine on every subsequent attempt.

Self-hosted Signal iOS is unable to connect to internet

same issue, other person: https://github.com/signalapp/Signal-iOS/issues/2282
We've checked out the Signal-iOS repository and we're trying to make it connect to another server. We're running an instance of the server at signal.appcraft.nl. We've modified the defines in SignalServiceKit/src/TSConstants.h to match our server and we've changed the domains in App Transport Security Settings in /Signal/Signal-Info.plist
We also cloned the Android app and that one we managed to got working just fine. The iOS app seems not to be able to connect to the internet at all without a clear error. The first HTTP call that is done is GET https://signal.appcraft.nl/v1/accounts/sms/code/<MYNUMBER>?client=ios. When we invoke that URL using curl, we get a response (and SMS) just fine. From the app, we receive a Signal was unable to connect to the internet. Please try from another WiFi network or use mobile data. error. We also changed NSAllowsArbitraryLoads to Yes.
We've added a breakpoint in /Signal-iOS/Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.m:292
# /Signal-iOS/Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.m:292
(lldb) expr error
(NSURLError *) $3 = 0x00000001c0244800 domain: #"NSURLErrorDomain" - code: 18446744073709550617
Please advise

Fetching cached objects in ServiceWorker - Failed

When I try to fetch the cached by checking the offline button in dev tools.Its getting no internet connection error and I tried with turning off my wifi its getting cached data.
Offline Button
Offline check in Chrome inspect tools fully simulates offline network state, so you do not have to turn off your modem, wifi or network adapter while using it.
Observing response source
You can go to Chrome inspect > Network panel and look at the size column to check the origin of a response. By just looking at there you will be able to tell a request is served from browser cache, service worker or from network.
The error
If you are getting error because of your sw.js while you are offline, it is not a problem. It simply means it could not get service worker from network and it does not have to get it while you are offline anyway. See this answer for a more detailed information about it.
I recommend you to install Lighthouse extension for chrome it makes the testing way easier and the reports are quite useful.
Are you checking the 'fetch' event for the cache files? And are you sure you have the files cached ?
self.addEventListener('fetch', function(event) {
console.log(event.request.url);
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});

Websocket in Rails app on Heroku is not working

I added a chat functionality in my existing RoR app with the websocket-rails (https://github.com/websocket-rails/websocket-rails) gem and I'm testing it in production mode on Heroku.
It works fine in localhost, but when I sent it to Heroku it is not receiving any further messages from the Server after the connection.
The connection works:
var WEBSOCKET_URL = 'myapponheroku.herokuapp.com/websocket'
var dispatcher = new WebSocketRails(WEBSOCKET_URL);
dispatcher.on_open = function(data) {
console.log('Connection has been established: ', data);
};
And I see the feedback message.
But the first task is to ask the server for active rooms in my chat. I noticed nothing is returning. I put some feedback messages in the server's action that should do the first tasks and none of them are reached. The feedback I implemented is a simple pair of functions that just returns a object and prints it to the console:
Javascript
dispatcher.bind('feedback',function(data){
console.log(data);
});
Ruby
def feedback data
send_message :feedback, {data: data}
end
It is never triggered. Any ideas? Is the a special configuration I must do on Heroku to allow it to work?
#update
Same error on my live server hosted on AWS.
Connection is established, but nothing is returned from server to client.
#update2
I wrote some code so the app would write some files when connection is established and when it asks for open rooms, right at the beginning, and the files were not created. The actions are not even being called.

iOS: How to run web service without open application after installed in iPhone

How to run web service without open application
I need to run an service without open the app.
Once app closed from background also it must be run service.
Its an security app like anti theft functionality.
Can anybody help to run service without open app ?
As far as I know you can not, from a browser, check if an app is installed or not.
But you can try redirecting the phone to the app, and if nothing happens redirect the phone to a specified page, like this:
setTimeout(function (){
window.location = "https://itunes.apple.com/appdir";
}, 25);
window.location = "appname://";
If the second line of code gives a result then the first row is never executed.
Hope this helps!
You can check the "Implementing long-running background tasks" section from Apple document.
or
You can use by local notification to do that. But this not check every time. You set the time to where you will check a particular event.
Here is the tutorial for creating Local Notification step by step.

Resources