[英]AWS Android Chat App
I am trying to make an android chat application. 我正在尝试制作一个Android聊天应用程序。 I am thinking about making it with aws.
我正在考虑用aws做。 But the problem is that I am unable to find any good tutorial for doing this and I have no idea how to do it.
但是问题是我找不到任何好的教程来做到这一点,而且我也不知道该怎么做。
So could anyone please suggest some tutorial for sending push notification or on how to make a chat application? 因此,有人可以建议一些有关发送推送通知或如何制作聊天应用程序的教程吗?
Firebase is well suited to this due to its "realtime database" feature. Firebase具有“实时数据库”功能,因此非常适合此操作。 Here's a few tutorials I found by Googling
这是我通过Googling找到的一些教程
Check Socket.IO for android. 检查Socket.IO for android。 ( https://github.com/socketio/socket.io-client-java )
( https://github.com/socketio/socket.io-client-java )
Its really easy to write a chat application. 编写聊天应用程序真的很容易。 But you need a server side.
但是您需要服务器端。 Easy to write a simple server for this chat app.
易于为该聊天应用编写简单的服务器。 Server reveice the all message from clients and broadcast the message, to all.
服务器显示来自客户端的所有消息,并将消息广播给所有人。
Gradle: 摇篮:
compile 'com.github.nkzawa:socket.io-client:0.5.1'
Android manifest: Android清单:
<uses-permission android:name="android.permission.INTERNET" />
Java 爪哇
public static Socket mSocket;
try {
mSocket = IO.socket("http://192.168.1.104:4444");
mSocket.connect();
} catch (URISyntaxException e) {
e.printStackTrace();
}
Send messsage to server: 发送消息到服务器:
MainActivity.mSocket.emit("message","Text here...");
Create a listener for another message: 创建另一个消息的侦听器:
MainActivity.mSocket.on("newMessage", onMessageArrive); // Oncreate
private Emitter.Listener onMessageArrive = new Emitter.Listener() {
@Override
public void call(final Object... args) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
String data = (String)args[0];
// Here is all message. add it to list :) Or Push notif
}
});
}
};
// Server side: // 服务器端:
var http = require('http');
var express = require('express'),
app = module.exports.app = express();
var io = require('socket.io').listen(app.listen(4444));
io.on('connection', function (socket) {
socket.on("message",function(msg){
io.sockets.emit('newMessage', msg);
});
});
Run: 跑:
npm install express
npm install socket.io
node filename.js
Just dont forget to check you IP! 只是不要忘记检查您的IP! :) Done!
:)完成! You have a Real Time Chat!!
您有实时聊天!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.