SocketChat
1.0.0
使用socket.io和android的简单聊天应用程序。创建于12-5-2021
1.安装socket.io依赖项构建。
dependencies {
...
implementation 'com.github.nkzawa:socket.io-client:0.6.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}
2. ADD Internet许可授予AndroidManifest.xml。
<uses-permission android:name="android.permission.INTERNET"/>
3.使用nodejs创建服务器
var socketIO = require('socket.io'),
http = require('http'),
port = process.env.PORT || 6000, // Port
ip = process.env.IP || '10.10.10.18', // My IP address
server = http.createServer().listen(port, ip, function() {
console.log("IP = " , ip);
console.log("start socket successfully");
});
io = socketIO.listen(server);
//io.set('match origin protocol', true);
io.set('origins', '*:*');
npm start
ipconfig