When I exit from the debugger and relaunch I often get the message:
Error: Error #2002: Operation attempted on invalid socket.
at flash.net::ServerSocket/internalBind()
at flash.net::ServerSocket/bind()
I usually have to wait a while before I can relaunch the application without the error.
How can I avoid this?
private function openConnection():void
{
_serverSocket = new ServerSocket();
_serverSocket.addEventListener(ServerSocketConnectEvent.CONNECT, onConnect)
_serverSocket.bind(888);
_serverSocket.listen();
}
private function onConnect(e:ServerSocketConnectEvent):void
{
trace("Client is connected");
_clientSocket = e.socket;
_clientSocket.addEventListener(ProgressEvent.SOCKET_DATA, onData);
_clientSocket.addEventListener(Event.CLOSE, onConnectionClosed);
}
I don't think you can avoid it. I it just takes awhile for the OS to free the socket after AIR lets go of it. As a workaround, you could catch the error and use a timer to retry binding the socket every few seconds.
And AIR apps never need policy files (unless the code opening the socket was loaded from outside the application).
Related
I have a project that included 3 windows services, the services were worked very well, then for business needs, we need to move from windows server 2008 to windows server 2019.
The issue which I faced is:
When I install the services, It didn't start and returned the error in the Event Viewer:
Service cannot be started. System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security, State.
I searched for this issue and I found a lot of answers ( like this) but it won't help me.
I installed the services in Command Line as administrator using InstallUtil.exe.
Then opened the Registry Editor and give the user NETWORK SERVICE a full control in the path as below:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog
Then I check the subkey of the services in the path:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application
Also, it exists.
My code related to EventLog :
public class EventViewer
{
public static void WriteEvent(string ServiceName, string msg, EventLogEntryType _EventLogEntryType)
{
EventLog eventLog = new EventLog();
eventLog.Source = ServiceName;
eventLog.Log = "Application";
((System.ComponentModel.ISupportInitialize)(eventLog)).BeginInit();
if (!EventLog.SourceExists(eventLog.Source))
{
EventLog.CreateEventSource(eventLog.Source, eventLog.Log);
}
((System.ComponentModel.ISupportInitialize)(eventLog)).EndInit();
eventLog.WriteEntry(msg, _EventLogEntryType);
}
}
The Event Viewer give me the line of the exception and it refers to:
((System.ComponentModel.ISupportInitialize)(eventLog)).BeginInit();
I tried to debug the service on my machine using Visual Studio 2019, but also give me the same error, and the service wouldn't start to debug using "Attach to Process".
I think the issue is while scanning the registry to check if the event source exist.
https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlog.createeventsource?view=dotnet-plat-ext-6.0
As per Microsoft the account requires administrative privilege to do this task.
I have also seen there is a new registry hive under 'EventLog' called 'state' in windows 2019 which has less access compared to other hives.
Debug with process monitor and see if you are getting access denied in that hive.
I am using the gulp-aemsync plugin to sync my css and js changes to a clientlib on an AEM instance. A have a gulp task watching the js and css that runs gulp-aemsync fine (changes are on the site when i refresh), but being a bit lazy as i am it would be nice to get live reload working so that i never have to manually refresh the page while working.
I have tried to follow both these 2 online guides:
https://adobe-consulting-services.github.io/acs-aem-tools/features/live-reload/index.html
https://www.cognifide.com/our-blogs/cq/up-and-running-with-livereload-in-adobe-aem6
Followed the steps of:
installing Netty package on AEM instance
installing ACS AEM tools package on the AEM instance
installing the RemoteLiveReload chrome extension (the AEM instance is hosted on AWS)
That didn't work, so i got one of our DevOps engineers to open port 35729 (which is the default for Livereload) on the AEM instance. That still doesn't work, and when i click the chrome browser extension to sync it i get the following message:
Could not connect to LiveReload server. Please make sure that LiveReload 2.3 (or later) or another compatible server is running.
Can anyone help me figure this out as i'd really like to get it working to streamline my workflow.
Thanks
DISCLAIMER: This answer is based on a setup I had working at some point, and by no means is a complete/working answer. But it should give you an alternative to the other tools that exist and get you half way there.
I have not used the tools you are mentioning, but since you are using gulp and aemsync, you could do the following:
In your gulp setup, create a websocket server and basically make that server publish messages everytime aemsync is triggered to push content to AEM.
// start a websocket server
const WebSocket = require('ws'); // requires "npm install ws"
const wss = new WebSocket.Server({ port: 8081 });
const connections = [];
wss.on('connection', function connection(ws) {
connections.push(ws); // keep track of all clients
// send any new messages that come to this server, to all connected clients
ws.on('message', (d) => connections.forEach(connection => connection.send(d)));
});
// create a new websocket to send messages to the websocket server above
const ws = new WebSocket('ws://localhost:8081');
// send a regex to the server every second
// NOTE: CHANGE this to run when aemsync is triggered in your build
setInterval( () => ws.send('reload'), 1000 );
Then in your JS code (on AEM) or really in a <script> tag that you make sure will NOT go beyond your local (or dev/prod) you can setup a websocket listener to refresh the page:
socket = new WebSocket('ws://localhost:8081');
socket.onopen = // add function for when ws is open
socket.onclose = // add function for when ws is closed
socket.onerror = // add function for when ws errors
// listen to messages and reload!
socket.addEventListener('message', function (event) {
location.reload();
});
Alternatively, you could use the chrome plugin I've developed:
https://github.com/ahmed-musallam/websocket-refresh-chrome-ext
It's not perfect by any means. However, for a basic setup, it should work great! an you don't need to touch your AEM JS.
I've implemented a task to run a server and react (reload) on changes of my source files.
export function serveDev (gulp) {
return () => {
const bs = browserSync.create();
const stream = bs.init(config.browsersync.opts);
gulp.watch(`${config.source}/components/**/*.js`, gulp.series('scripts'));
gulp.watch(`${config.source}/js/**/*.js`, gulp.series('scripts'));
gulp.watch(config.browsersync.watch).on('change', bs.reload);
return stream;
};
}
I'm using gulp-4.0 and I'm running this task from the command line.
What's the correct implementation to terminate this task correctly when the user hits CTRL+C?
When I terminate this running task with the key-shortcut CTRL+C I get the following error:
The following tasks did not complete: serve, sync
Did you forget to signal async completion?
The task is working properly until the user hits CTRL+C. When the signal coming from CTRL+C reach the task the error described above is printed out. I would like to know how to catch or how to react properly on the termination signal coming from CTRL+C?
You can kill the background process on terminal with pkill command like:
pkill gulp
I am using Prosody for stream management. But I am suffering from some issues.
How can I ensure that stream management is enabled on prosody ? Is there any command to test on terminal ?
I also tried to add mod_smacks.lua modules in modules. but I don't know how to enable it on server.
I am using XMPPFramework as chat client on iOS. There is already a method to check support for stream management or not, but it is returning me always false so far.
Please help me out to enable stream management in prosody.
After you added mod_smacks.lua into your /usr/lib/prosody/modules/ add
"smacks";
to your
modules_enabled = {
...
}
in your /etc/prosody/prosody.cfg.lua if you want the module to be loaded every time prosody starts.
Then restart prosody.
Prosodyctl does not show loaded modules.
You can check if the module is loaded via ad-hoc commands (or telnet if activated). You can even load and unload modules via ad-hoc/telnet.
You get more information about mod_smacks here.
I am trying to create some karma tests and some of the functions I'm testing are supposed to make Websocket connections.
When running the code normally outside of Karma (using Chrome or Firefox), I see that my console log messages show that ws.onopen() fires as expected.
Not so when running in Karma using PhantomJS or even Chrome. I'm running version 0.12 of Karma. Could this be related to how Karma uses socket.io, instead of the browser's Websocket?
I am not doing anything in regards to manually writing a handshake.
webSocketConnect = function() {
ws = new WebSocket("ws://192.168.103.83:9000", "ws-xyz");
ws.onopen = function(evt) {
console.log("Connection is opened...");
};
};
When webSocketConnect is invoked, i.e.:
webSocketConnect();
I get no error but I don't see "Connection is opened..." in the console log.
Thanks for any help.
Edit: I think that the code is not getting executed because XSS protections are coming into play. I took the code above and started playing around with it in jsfiddle and saw that when I ran it I would get: "
SecurityError: The operation is insecure." I think it's a shame that Karma is not reporting any error. In fact Karma is completely silent and I wasn't even noticing that none of the websocket code was being executed at all.