谁能提供一个html5消息推送的实例,服务端为asp.net?谢谢

UlikeLeo 2014-04-05 01:24:44
谁能提供一个html5消息推送的实例,服务端为asp.net,谢谢!
...全文
964 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
shangjinlieren_1 2016-07-07
  • 打赏
  • 举报
回复
GoEasy Web实时推送工具,轻松实现实时消息推送。 Web页面订阅(约5行代码),服务器端推送(2行代码)就可以轻松实现,而且在高并发时消息推送稳定。 自己完全可以只花五分钟写出属于自己的第一个实时推送功能!感兴趣的朋友可以到他们官网上看一下。https://goeasy.io
业余草 2015-12-08
  • 打赏
  • 举报
回复
asp ,你多搜搜,asp 动态语言部分?接触不多
hhhh63 2014-08-18
  • 打赏
  • 举报
回复
定时刷新也行,省资源
Cheris2014 2014-08-13
  • 打赏
  • 举报
回复
java部分 import java.io.IOException; import java.nio.ByteBuffer; import java.nio.CharBuffer; import javax.servlet.http.HttpServletRequest; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; import org.apache.catalina.websocket.MessageInbound; import org.apache.catalina.websocket.StreamInbound; import org.apache.catalina.websocket.WsOutbound; import org.apache.catalina.websocket.WebSocketServlet; public class SocketServer extends WebSocketServlet { private static final long serialVersionUID = 1L; public final Set<ChatWebSocket> users = new CopyOnWriteArraySet<ChatWebSocket>(); public static int USERNUMBER = 1; @Override protected StreamInbound createWebSocketInbound(String arg0, HttpServletRequest arg1) { // TODO Auto-generated method stub return new ChatWebSocket(users); } public class ChatWebSocket extends MessageInbound { private String username; private Set<ChatWebSocket> users = new CopyOnWriteArraySet<ChatWebSocket>();; public ChatWebSocket() { } public ChatWebSocket(Set<ChatWebSocket> users) { this.users = users; } @Override protected void onTextMessage(CharBuffer message) throws IOException { // 这里处理的是文本数据 } public void onMessage(String data) { String[] val1 = data.split("\\t"); if(val1[0].equals("NAME")) { String[] val2=val1[1].split("_"); for(ChatWebSocket user:users){ if (user.username.equals(val2[0])){ user.username=val2[1]; } } } else if(val1[0].equals("MSG")) { String[] val2=val1[1].split("_"); for(ChatWebSocket user:users){ if (user.username.equals(val2[1])){ try { CharBuffer temp=CharBuffer.wrap(data); user.getWsOutbound().writeTextMessage(temp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } else { System.out.println("ERROR"); } } @Override protected void onOpen(WsOutbound outbound) { // this.connection=connection; this.username = "#" + String.valueOf(USERNUMBER); USERNUMBER++; try { String message = "NAME" + "\t" + this.username; CharBuffer buffer = CharBuffer.wrap(message); this.getWsOutbound().writeTextMessage(buffer); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } users.add(this); } @Override protected void onClose(int status) { users.remove(this); } @Override protected void onBinaryMessage(ByteBuffer arg0) throws IOException { } } }
Cheris2014 2014-08-13
  • 打赏
  • 举报
回复
程序代码 html部分 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/socket.js"></script> <title>无标题文档</title> </head> <script language="javascript"> </script> <body> <table> <tr> <td>Message</td> <td><input type="text" id="message"></td> </tr> <tr> <td>Name</td> <td><input type="text" id="othername"></td> </tr> <tr> <td><input id="sendbutton" type="button" value="send" onClick="click" disabled="true"> </input></td> </tr> </table> <script> </script> </body> </html> js部分(关于jquery部分不进行讲解) var username = window.prompt("输入你的名字:"); document.write("Welcome<p id=\"username\">"+username+"</p>"); if (!window.WebSocket && window.MozWebSocket) window.WebSocket=window.MozWebSocket; if (!window.WebSocket) alert("No Support "); var ws; $(document).ready(function(){ $("#sendbutton").attr("disabled", false); $("#sendbutton").click(sendMessage); startWebSocket(); }) function sendMessage() { var othername=$("#othername").val(); var msg="MSG\t"+username+"_"+othername+"_"+$("#message").val(); send(msg); } function send(data) { console.log("Send:"+data); ws.send(data); } function startWebSocket() { ws = new WebSocket("ws://" + location.host + "/WebSocket/SocketServer"); ws.onopen = function(){ console.log("success open"); $("#sendbutton").attr("disabled", false); }; ws.onmessage = function(event) { console.log("RECEIVE:"+event.data); handleData(event.data); }; ws.onclose = function(event) { console.log("Client notified socket has closed",event); }; } function handleData(data) { var vals=data.split("\t"); var msgType=vals[0]; switch(msgType) { case "NAME": var msg=vals[1]; var mes="NAME"+"\t"+msg+"_"+ username; send(mes); break; case "MSG": var val2s=vals[1].split("_"); var from=val2s[0]; var message=val2s[2]; alert(from+":"+message); break; default: break; } }
Cheris2014 2014-08-13
  • 打赏
  • 举报
回复
html5利用websocket完成的推送功能 链接:http://www.alixixi.com/web/a/2014032492868.shtml 希望能帮到你!
业余草 2014-06-21
  • 打赏
  • 举报
回复
websocket,你可以看一看的哦
liuxing19870629 2014-04-14
  • 打赏
  • 举报
回复
不太明白你要的功能,不过你可以看下Web Workers是不是你需要的

39,084

社区成员

发帖
与我相关
我的任务
社区描述
HTML5是构建Web内容的一种语言描述方式。HTML5是互联网的下一代标准,是构建以及呈现互联网内容的一种语言方式.被认为是互联网的核心技术之一。
社区管理员
  • HTML5社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧