private static final String GOOGLE_SETTINGS_ACTIVITY = ".app.settings.GoogleSettingsActivity"
private static final String GOOGLE_SETTINGS_COMPONENT = "com.google.android.gms";
Intent i = new Intent();
i.setClassName(GOOGLE_SETTINGS_COMPONENT,
GOOGLE_SETTINGS_COMPONENT + GOOGLE_SETTINGS_ACTIVITY);
try {
startActivity(i);
} catch (android.content.ActivityNotFoundException ex) {
// activity not found.
}
Wednesday, November 18, 2015
How to open Google Settings app programmatically?
Wednesday, October 14, 2015
SW REV CHECK FAIL DEVICE 2 BINARY 1 In Samsung G925 Android 5.1.1
Today I was flashing my Samsung S6 from Android 5.0.2 to Android 5.1.1. So I downloaded tar.md5 file from Samsung fired up Odin and started flashing and out of no where Flash failed!. Then when I tried to flash Android 5.0.1 again I started getting this error
It shows this error on device screen
Reason for this error is during the previous flash it upgraded the bootloader to 5.11 and now it is refusing to go back to an older version. You cannot flash 5.0.1 bootloader again. You have to stay with Android 5.11
Then I tried Samsung Smart Switch and it managed to recover the phone from Soft brick and complete Android 5.1.1 installation and it it boots file.
As a another solution, You can
1. Download the tar.md5 file.
2. Rename the file back to tar and extract
3. Delete hidden.img
4. Download this toolkit http://forum.xda-developers.com/galaxy-s6-edge/orig-development/toolkit-skipsoft-android-toolkit-galaxy-t3101195
5. Make your own firmware
6. Flash
Tip: https://www.reddit.com/r/GalaxyS6/comments/35zshn/howto_fix_a_failed_odin_flash_softbrick_hiddenimg/
It shows this error on device screen
SW REV CHECK FAIL DEVICE 2 BINARY 1
<ID:0/003> Added!!
<OSM> Enter CS for MD5..
<OSM> Check MD5.. Do not unplug the cable..
<OSM> Please wait..
<OSM> G925FXXU1AOCV_G925FVIR1AOCN_G925FXXU1AOCW_HOME.tar .md5 is valid.
<OSM> Checking MD5 finished Sucessfully..
<OSM> Leave CS..
<ID:0/003> Odin engine v(ID:3.1005)..
<ID:0/003> File analysis..
<ID:0/003> SetupConnection..
<ID:0/003> Initialzation..
<ID:0/003> Get PIT for mapping..
<ID:0/003> Firmware update start..
<ID:0/003> SingleDownload.
<ID:0/003> sboot.bin
<ID:0/003> NAND Write Start!!
<ID:0/003> FAIL!
<ID:0/003>
<ID:0/003> Complete(Write) operation failed.
<OSM> All threads completed. (succeed 0 / failed 1)
Reason for this error is during the previous flash it upgraded the bootloader to 5.11 and now it is refusing to go back to an older version. You cannot flash 5.0.1 bootloader again. You have to stay with Android 5.11
Then I tried Samsung Smart Switch and it managed to recover the phone from Soft brick and complete Android 5.1.1 installation and it it boots file.
As a another solution, You can
1. Download the tar.md5 file.
2. Rename the file back to tar and extract
3. Delete hidden.img
4. Download this toolkit http://forum.xda-developers.com/galaxy-s6-edge/orig-development/toolkit-skipsoft-android-toolkit-galaxy-t3101195
5. Make your own firmware
6. Flash
Tip: https://www.reddit.com/r/GalaxyS6/comments/35zshn/howto_fix_a_failed_odin_flash_softbrick_hiddenimg/
Thursday, October 1, 2015
Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES] hell
Today I wanted to install a newer version on top of existing version of my app. So as usual I did
It threw
Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]
But why ? So I wanted to check whether certificate has really changed since the last version. To do this, you need to unzip the apk file and check inside.
1. Unzip the apk file.
2. Goto META-INF folder
3. "CERT.RSA" file is used to verify the signature
So, Now you need to look at whats the signature looks like. To do that,
keytool -printcert -file CERT.RSA
Will output something like
And when I compare with the newer version
It appear newer version of the android build tool (23) is using SHA256withRSA and older version (17) was using SHA1withRSA
adb install -r app.apk
It threw
Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]
But why ? So I wanted to check whether certificate has really changed since the last version. To do this, you need to unzip the apk file and check inside.
1. Unzip the apk file.
2. Goto META-INF folder
3. "CERT.RSA" file is used to verify the signature
So, Now you need to look at whats the signature looks like. To do that,
keytool -printcert -file CERT.RSA
Will output something like
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: xxx
Valid from: Thu Aug 01 14:20:26 ICT 2013 until: Sat Jul 25 14:20:26 ICT 2043
Certificate fingerprints:
MD5: xxxx
SHA1: xxxx
Signature algorithm name: SHA1withRSA
Version: 3
And when I compare with the newer version
"Signature algorithm name: SHA256withRSA"
It appear newer version of the android build tool (23) is using SHA256withRSA and older version (17) was using SHA1withRSA
Tuesday, September 15, 2015
How to setup USB audio card in Raspberry Pi 2
sudo nano /etc/modprobe.d/alsa-base.conf
Change this line to
options snd-usb-audio index=-2 to options snd-usb-audio index=1
This will enable USB audio output by default. Reboot now:
sudo reboot
After reboot, To play a sound
aplay -D plughw:1,0 /usr/share/sounds/alsa/Front_Left.wav
if it does not work
cat /proc/asound/modules
Displays:
0 snd_bcm2835
1 snd_usb_audio
aplay -D plughw:0,0 /usr/share/sounds/alsa/Front_Left.wav
aplay -D plughw:1,0 /usr/share/sounds/alsa/Front_Left.wav
Change this line to
options snd-usb-audio index=-2 to options snd-usb-audio index=1
This will enable USB audio output by default. Reboot now:
sudo reboot
After reboot, To play a sound
aplay -D plughw:1,0 /usr/share/sounds/alsa/Front_Left.wav
if it does not work
cat /proc/asound/modules
Displays:
0 snd_bcm2835
1 snd_usb_audio
aplay -D plughw:0,0 /usr/share/sounds/alsa/Front_Left.wav
aplay -D plughw:1,0 /usr/share/sounds/alsa/Front_Left.wav
Wednesday, September 9, 2015
How to get the pid of a process using Java code in Android.
public static String pidOf(String lookFor) {
String line;
String pid=null;
boolean applicationIsOk = false;
Process proc = null;
try {
proc = Runtime.getRuntime().exec("ps");
} catch (IOException e) {
e.printStackTrace();
}
if(proc != null) {
InputStream stream = proc.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
try {
while ((line = reader.readLine()) != null) {
Pattern pattern = Pattern.compile(lookFor);
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
String[] splited = line.split("\\s+");
if(splited.length>3){
int p = -1;
try {
p = Integer.parseInt(splited[1]);
}catch(NumberFormatException nf){
e.printStackTrace();
}
if(p>0){
pid = new String(splited[1]);
}
}
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
return pid;
}
String line;
String pid=null;
boolean applicationIsOk = false;
Process proc = null;
try {
proc = Runtime.getRuntime().exec("ps");
} catch (IOException e) {
e.printStackTrace();
}
if(proc != null) {
InputStream stream = proc.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
try {
while ((line = reader.readLine()) != null) {
Pattern pattern = Pattern.compile(lookFor);
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
String[] splited = line.split("\\s+");
if(splited.length>3){
int p = -1;
try {
p = Integer.parseInt(splited[1]);
}catch(NumberFormatException nf){
e.printStackTrace();
}
if(p>0){
pid = new String(splited[1]);
}
}
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
return pid;
}
Wednesday, August 19, 2015
How to set PACKAGE_VERIFIER_ENABLE hidden API attribute?
How to enable Settings.Secure.PACKAGE_VERIFIER_ENABLE settings via adb shell ?
root@trelte:/ # settings put global package_verifier_enable 0
root@trelte:/ # settings put global package_verifier_enable 0
Friday, August 14, 2015
How to get the device id using adb shell ?
How to get the device id via adb shell ?
adb shell settings get secure android_id
adb shell settings get secure android_id
Sunday, July 26, 2015
python: can't open file '\bin\cfx': [Errno 2] Mozilla extension development
Today, I downloaded Mozilla SDK on my 64-bit Windows 7 PC and ran cfx init command to start. Then it threw this error
When i opened cfx.bat file in the SDK\bin folder, it was looking for an environment variable called %VIRTUAL_EVN%
When I looked at my PC's environment variable list, I could not find it there. So I created it and pointed it to the SDK folder. (Not the bin folder) then error disappeared.
python: can't open file '\bin\cfx'
When i opened cfx.bat file in the SDK\bin folder, it was looking for an environment variable called %VIRTUAL_EVN%
When I looked at my PC's environment variable list, I could not find it there. So I created it and pointed it to the SDK folder. (Not the bin folder) then error disappeared.
Monday, July 20, 2015
How to recognize that CyanogenMod in Android
static public boolean checkCyanogenMod() {
final Properties properties = System.getProperties();
String version = properties.getProperty("os.version");
final PackageManager pm = getAppContext().getPackageManager();
if (version.contains("cyanogenmod") || version.contains("-CM-")
|| pm.hasSystemFeature("com.cyanogenmod.account")
|| pm.hasSystemFeature("com.cyanogenmod.updater")) {
return true;
}
return false;
}
Tuesday, June 9, 2015
NodeJS installer (.msi) ended prematurely without showing anything on Vista
Today, I wanted to update my node.js version from 0.10 to 0.12. As usual I uninstalled the 0.10 version and try to install via node-v0.12.4-x64.msi and it seems to be ending without showing any dialogs.
So, I wanted to check the installer log. When I did this it showed the UI
msiexec /i "C:\Users\aruna\Desktop\node-v0.12.4-x64.msi" /L*V "C:\Users\aruna\Desktop\mymsi.log"
So, I wanted to check the installer log. When I did this it showed the UI
msiexec /i "C:\Users\aruna\Desktop\node-v0.12.4-x64.msi" /L*V "C:\Users\aruna\Desktop\mymsi.log"
Thursday, May 21, 2015
500 Internal Server Error in nodejs/express after 1000+ clients connected
Today, I moved the server to a Rackspace. As usual I tested the everthing before moving to the new server and all worked well. After chaning DNS to point the new server I started to notice server showing Internal Server Error when it hits 1000 + concurrent users. So, I enabled logs in express to see whats is going on.
// log every request to the logger
app.use(morgan('combined', {stream: log.stream}));
This showed that client request hits the server, however it has a problem rendering the output page but why after hitting 1000 + users? Then it hit me, it must have ran out of file descriptors.
The aha moment. It is hitting the ulimit. So I changed the ulimit
All worked fine after that. However ulimit seems to me temporary. To make permenet changes you must change few things.
1) Increase max number of ulimit open file in Linux
2) sudo nano /etc/security/limits.conf and add below the mentioned
3) sudo nano /etc/security/limits.d/90-nproc.conf. Change to
// log every request to the logger
app.use(morgan('combined', {stream: log.stream}));
This showed that client request hits the server, however it has a problem rendering the output page but why after hitting 1000 + users? Then it hit me, it must have ran out of file descriptors.
$ ulimit -n
1024.
The aha moment. It is hitting the ulimit. So I changed the ulimit
$ ulimit -n 2048
All worked fine after that. However ulimit seems to me temporary. To make permenet changes you must change few things.
1) Increase max number of ulimit open file in Linux
sudo nano /etc/sysctl.conf add end of line fs.file-max = 65536
2) sudo nano /etc/security/limits.conf and add below the mentioned
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
3) sudo nano /etc/security/limits.d/90-nproc.conf. Change to
* soft nproc 65535
root soft nproc unlimited
Tuesday, May 19, 2015
How to install a system app in Android 5.0 or later devices ?
Rename your apk file to base.apk
Reboot your device. When boot completes you should see a system message like Android updating ...
$ adb push base.apk /sdcard/
$ adb shell
$ su
$ mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
$ mkdir /system/app/Test
$ chmod 755 /system/app/Test
$ cat /sdcard/base.apk > /system/app/Test/Base.apk
$chmod 644 /system/app/Test/Base.apk
$ mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system
$ exit
Reboot your device. When boot completes you should see a system message like Android updating ...
Monday, May 18, 2015
How to check whether Android is running 64 bit version
If you want to check whether your device is running 64 bit version you can check System.getProperty("os.arch"). This will return aarch64 on Samsung S6.More safe approach would be
This does not work on Nexus 5x. Because Nexus 5x returnsboolean is64 = System.getProperty("os.arch").contains("64");
armv8l
So, I changed my code to
boolean is64 = System.getProperty("ro.product.cpu.abilist").contains("64");
You can use shell command to check as well
shell@zerolte:/ $ uname -m
uname -m
aarch64
Thursday, May 14, 2015
WARNING: linker: could not load library "libsigchain.so" from LD_PRELOAD for "sh"; caused by "libsigchain.so" is 32-bit instead of 64-bit CANNOT LINK EXECUTABLE: could not load library "libc.so" needed by "sh"; caused by "libc.so" is 32-bit instead of 64-bit
I have been trying to fix my app to support Samsung S6. It seems Samsung S6 Android 5.0.2 runs in 64 bit. If you are seeing this error it is likely "libsigchain.so" is loaded from wrong location.
If you execute this command in shell,
root@zerolte:/ # printenv "LD_PRELOAD"
printenv "LD_PRELOAD"
libsigchain.so
you libsigchain.so likely being loaded from /system/lib. To fix
export LD_PRELOAD = /system/lib64/libsigchain.so
Or you can try something like this:
final String extStoreApkPath = ""
final String libPath = (is64bit() ? "/vendor/lib:/system/lib64" : "/vendor/lib:/system/lib");
final String cmd = String.format("LD_LIBRARY_PATH=%s pm install -r -d %s", libPath, extStoreApkPath);
ERROR: ld.so: object ‘/system/lib/libsigchain.so’ from LD_PRELOAD cannot be preloaded: ignored
To fix this problem just run unset LD_PRELOAD
Thursday, March 5, 2015
Android WorkerThread class
import android.os.Handler;
import android.os.Looper;
import java.util.concurrent.Executor;
class WorkerThread extends Thread implements Executor {
private Handler handler;
private boolean isAlive = false;
public WorkerThread() {
super("WorkerThread-" + System.currentTimeMillis());
}
public void run() {
Looper.prepare();
this.isAlive = true;
this.handler = new Handler();
synchronized (this) {
super.notifyAll();
}
Looper.loop();
}
public Handler getHandler() {
return this.handler;
}
public void stopThread() {
this.isAlive = false;
this.handler.getLooper().quit();
this.handler.removeCallbacksAndMessages(null);
}
public static WorkerThread createWorkerThread() {
WorkerThread thread = new WorkerThread();
synchronized (thread) {
thread.start();
try {
thread.wait();
} catch (InterruptedException e) {
throw new RuntimeException();
}
return thread;
}
}
public void execute(Runnable command)
{
if (this.isAlive)
this.handler.post(command);
}
}
How to check whether device is rooted in Android
Normally we detect whether device is rooted by checking for su binary. Problem is su binary can be in many location based on rooting techniques.
protected static boolean checkForRoot()
{
String[] arrayOfString = new String[8];
arrayOfString[0] = "/sbin/";
arrayOfString[1] = "/system/bin/";
arrayOfString[2] = "/system/xbin/";
arrayOfString[3] = "/data/local/xbin/";
arrayOfString[4] = "/data/local/bin/";
arrayOfString[5] = "/system/sd/xbin/";
arrayOfString[6] = "/system/bin/failsafe/";
arrayOfString[7] = "/data/local/";
int j = arrayOfString.length;
int i = 0;
while (i < j)
{
String str = arrayOfString[i];
if (new File(str + "su").exists()) {
return true;
}
i += 1;
}
return false;
}
Sunday, February 22, 2015
How to insert a line into a file in NodeJS
How to insert a text in to a specific line in a text file using NodeJS.
function insertLine(file, lineNumber, insertText) {
var array = fs.readFileSync(file).toString().split("\n");
array.splice((lineNumber - 1), 0, insertText); fs.writeFileSync(file, array.join('\n'), 'utf8');
}
Friday, February 13, 2015
Fonts are distorted/blur after Windows Update in Vista 32/64 bit
After yesterday Windows Update (KB3013455) Courier New front got distorted very bad in my PC. It got bad to the level that it is not longer readable. This font change affected everywhere. Chrome, Notepad ++ ect and i was super mad for half of the day looking for a solution.
to fix this problem you must uninstall KB3013455 from Windows Updates and reboot the device
Monday, January 19, 2015
how to make a application wide locale change in Andorid
Today, While testing on Arabic language I found that app cannot query data from the database due to Arabic numeral system being different from English. So, I decided to enforce English on whole language
In the Manifest,
<application
android:name="MyApplication" >
Code:
public class MyApplication extends Application {
@Override
public void onCreate()
{
switchLocale()
super.onCreate();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
switchLocale();
}
}
public static void switchLocale(Context context) {
try {
Locale currentLocale = Locale.getDefault();
if(currentLocale != null) {
if (currentLocale != Locale.US || currentLocale != Locale.UK) {
final String languageToLoad = "en";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, null);
}
}
} catch (Throwable e) {
}
}
Monday, January 12, 2015
Android Booting Sequence Stages Step By Step
Android Booting Sequence Step By Step
In Booting of Android OS from power on
Stage 1 : Power on and boot ROM code execution
Stage 2 : The boot loader loading
Stage 3 : Starting of Linux kernel
Stage 4 : The init process
Stage 5 : Zygote and Dalvik
Stage 6 : The system server initiation
Stage 1 Power on and boot ROM code execution
At power on the CPU will be in a state where no initializations have been done. Internal clocks are not set up and the only memory available is the internal RAM.
When power supplies are stable the execution will start with the Boot ROM code. The Boot ROM code will detect the boot media using a system register that maps to some physical balls on the ASIC. This is to determine where to find the first stage of the boot loader.
Once the boot media sequence is established the boot ROM will try to load the first stage boot loader to internal RAM. Once the boot loader is in place the boot ROM code will perform a jump and execution continues in the boot loader.
Stage 2 The boot loader loading
The first boot loader stage will detect and set up external RAM.
Once external RAM is available and the system is ready the to run something more significant the first stage will load the main boot loader and place it in external RAM.
The second stage of the boot loader is the first major program that will run. This may contain code to set up file systems, additional memory, network support, loading code for the modem CPU and setting up low level memory protections and security options.
Once the boot loader is done with any special tasks it will look for a Linux kernel to boot. It will load this from the boot media (or some other source depending on system configuration) and place it in the RAM.
Once the boot loader is done it will perform a jump to the Linux kernel, usually some decompression routine, and the kernel assumes system responsibility
Stage 3 Starting of Linux kernel
It will set up everything that is needed for the system to run. Initialize interrupt controllers, set up memory protections, caches and scheduling.
Once the memory management units and caches have been initialized the system will be able to use virtual memory and launch user space processes.
The kernel will look in the root file system for the init process (found under system/core/init in the Android open source tree) and launch it as the initial user space process.
Stage 4 The init process
The init process in Android will look for a file called init.rc. This is a script that describes the system services, file system and other parameters that need to be set up. The init.rc script is placed in system/core/rootdir in the Android open source project.
The init process will parse the init script and launch the system service processes.
Stage 5 Zygote and Dalvik
init runs the C++ program /system/bin/app_process, and gives the resulting process the name "zygote"
app_process executes, and executes a runtime environment for a dalvik class
app_process does a 'runtime.start("com.android.internal.os.ZygoteInit", startSystemServer)
com.android.internal.os.ZygoteInit:main() starts executing
The profiler is started the Zygote socket is registered (for later communication to start apps) classes and resources are preloaded if startSystemServer is set, then the system server is started
Zygote runs in "select loop mode", where a single process spins waiting for communication to start subsequent apps.
Eventually, a call is made to Zygote.forkAndSpecialize(), which does the actual forking
Stage 6 The system server initiation
The system server is the first java component to run in the system. It will start all the Android services such as telephony manager and bluetooth. Start up of each service is currently written directly into the run method of the system server. source can be found in the file frameworks/base/services/java/com/android/server/SystemServer.java in the open source project. Once the System Server is up and running and the system boot has completed there is a standard broadcast action called ACTION_BOOT_COMPLETED. To start your own service, register an alarm or otherwise make your application perform some action after boot you should register to receive this broadcast intent .
In Booting of Android OS from power on
Stage 1 : Power on and boot ROM code execution
Stage 2 : The boot loader loading
Stage 3 : Starting of Linux kernel
Stage 4 : The init process
Stage 5 : Zygote and Dalvik
Stage 6 : The system server initiation
Stage 1 Power on and boot ROM code execution
At power on the CPU will be in a state where no initializations have been done. Internal clocks are not set up and the only memory available is the internal RAM.
When power supplies are stable the execution will start with the Boot ROM code. The Boot ROM code will detect the boot media using a system register that maps to some physical balls on the ASIC. This is to determine where to find the first stage of the boot loader.
Once the boot media sequence is established the boot ROM will try to load the first stage boot loader to internal RAM. Once the boot loader is in place the boot ROM code will perform a jump and execution continues in the boot loader.
Stage 2 The boot loader loading
The first boot loader stage will detect and set up external RAM.
Once external RAM is available and the system is ready the to run something more significant the first stage will load the main boot loader and place it in external RAM.
The second stage of the boot loader is the first major program that will run. This may contain code to set up file systems, additional memory, network support, loading code for the modem CPU and setting up low level memory protections and security options.
Once the boot loader is done with any special tasks it will look for a Linux kernel to boot. It will load this from the boot media (or some other source depending on system configuration) and place it in the RAM.
Once the boot loader is done it will perform a jump to the Linux kernel, usually some decompression routine, and the kernel assumes system responsibility
Stage 3 Starting of Linux kernel
It will set up everything that is needed for the system to run. Initialize interrupt controllers, set up memory protections, caches and scheduling.
Once the memory management units and caches have been initialized the system will be able to use virtual memory and launch user space processes.
The kernel will look in the root file system for the init process (found under system/core/init in the Android open source tree) and launch it as the initial user space process.
Stage 4 The init process
The init process in Android will look for a file called init.rc. This is a script that describes the system services, file system and other parameters that need to be set up. The init.rc script is placed in system/core/rootdir in the Android open source project.
The init process will parse the init script and launch the system service processes.
Stage 5 Zygote and Dalvik
init runs the C++ program /system/bin/app_process, and gives the resulting process the name "zygote"
app_process executes, and executes a runtime environment for a dalvik class
app_process does a 'runtime.start("com.android.internal.os.ZygoteInit", startSystemServer)
com.android.internal.os.ZygoteInit:main() starts executing
The profiler is started the Zygote socket is registered (for later communication to start apps) classes and resources are preloaded if startSystemServer is set, then the system server is started
Zygote runs in "select loop mode", where a single process spins waiting for communication to start subsequent apps.
Eventually, a call is made to Zygote.forkAndSpecialize(), which does the actual forking
Stage 6 The system server initiation
The system server is the first java component to run in the system. It will start all the Android services such as telephony manager and bluetooth. Start up of each service is currently written directly into the run method of the system server. source can be found in the file frameworks/base/services/java/com/android/server/SystemServer.java in the open source project. Once the System Server is up and running and the system boot has completed there is a standard broadcast action called ACTION_BOOT_COMPLETED. To start your own service, register an alarm or otherwise make your application perform some action after boot you should register to receive this broadcast intent .
Monday, January 5, 2015
How to start express and websocket server in same port in NodeJS?
How to use the same port to start the web server (express) and web socket server in the same port in NodeJS ?
//app.js
var WebSocketServer = require('ws').Server
, http = require('http')
, express = require('express')
, app = express();
app.use(express.static(__dirname + '/'));
var server = http.createServer(app);
var wss = new WebSocketServer({server:server});
wss.on('connection', function (ws) {
ws.on('close', function () {
console.log('close:');
});
ws.on('message', function (message) {
console.log('message:', message);
});
});
server.listen(3000);
Subscribe to:
Posts (Atom)