chat

Flask基于websocket的简单聊天室

匿名 (未验证) 提交于 2019-12-02 21:53:52
1、安装gevent-websocket pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ gevent-websocket 2、chat.py文件内容如下: from flask import Flask,request,render_template import json from geventwebsocket.handler import WebSocketHandler from gevent.pywsgi import WSGIServer from geventwebsocket.websocket import WebSocket user_dict = {} chat_app = Flask(__name__) @chat_app.route('/ws/<username>') def ws_chat(username): user_socket = request.environ.get('wsgi.websocket') # type:WebSocket user_dict[username]=user_socket while 1: msg = user_socket.receive() # 等待接收客户端发来的数据 msg_dict = json.loads(msg) msg_dict[

Spring boot 工具类静态属性注入及多环境配置

匿名 (未验证) 提交于 2019-12-02 21:53:32
由于需要访问MongoDB,但是本地开发环境不能直接连接MongoDB,需要通过SecureCRT使用127.0.0.2本地IP代理。但是程序部署到线上生产环境后,是可以直接访问MongoDB的,因此开发好程序后,总是要修改一下MongoDB服务器的IP才能提交代码,这样很是不方便。 private static final String PUBCHAT_HOST = "127.0.0.2"; // private static final String PUBCHAT_HOST = "PROD_MONGO_SERVER_IP"; 由于没有使用spring-boot自带的 spring-boot-starter-data-mongodb ,而是使用 mongo-java-driver 访问MongoDB,因此在程序中需要定义一些访问MongoDB的配置,比如服务器地址、IP端口、数据库名……使用一个工具类的静态变量声明这些配置信息,配置信息的值保存在application.yml 配置文件中。通过 @ConfigurationProperties 注入。 属性是静态的: private static String chat_username; 然后通过非静态的 set方法注入: @Value("${mongo.config.username}") public void

Chatroom in C / Socket programming in Linux

▼魔方 西西 提交于 2019-12-02 21:13:22
I have a simple server and client C code to do a chatroom for multiclients using threads (pthread library). The problem I've been having is that I can't think a way of making the server write every message that a client sends over the socket into all other clients. I've read other similar posts in here and it was helpless. Please help me I need to do this for school. I'll send both codes right away. Server.c: #include<stdio.h> #include<string.h> //strlen #include<stdlib.h> //strlen #include<sys/socket.h> #include<arpa/inet.h> //inet_addr #include<unistd.h> //write #include<pthread.h> //for

iOS chat APNS, sockets or time interval [closed]

吃可爱长大的小学妹 提交于 2019-12-02 20:28:14
I'm making a chat app for iPhone, but im not sure how conversation messages should come instantly. I have read tons of Google results on this topic. Also the once on: - http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server - http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12 APNS approach: An invisible notification will be pushed to the iPhone indicating that a new message is ready to be read. So the app will make a request for unread messages. So instead of manually polling new messages, I will let APNS help with that. But I'm

How do I use php so that when a user presses a specific button, they can write to a specific .txt file?

回眸只為那壹抹淺笑 提交于 2019-12-02 20:10:32
问题 Basically, as in other questions I've asked related to my php chat application, I am trying to get it so that there is a text field where $msg is displayed via msg.txt. Two users can communicate to another in this way. This would be easy if I wanted to use a simple include function. But I don't want to take all the trouble to make and upload all those pages to my server. So how can I have it where when the user, say named Aaron, clicks on a button titled Benjamin, and types to a file called

Ruby on Rails 3 - Public live chat

核能气质少年 提交于 2019-12-02 19:47:37
I want to create a public live chat application using rails 3. I found some example on rails 2. Any one can tell you a good example / tutorial to develop a live chat application using rails 3. I'd start by checking out Ilya Grigorik's em-synchony + examples and looking at the code for the Hector private chat server gem. I encountered several roadblocks as I tried to implement a public and private chat system in my rails 3 app. I looked at faye, juggernaut, node.js and more. Eventually after trying several approaches I was able to implement a system that works great: 1) I started by following

SignalR multiple chat rooms

三世轮回 提交于 2019-12-02 19:45:29
I am planning to create a chat application, and I've read that SignalR is one of the best technologies to apply. I've seen examples of it, but they only have a single chat room. I want to have multiple chat rooms. The user will just choose one of those chat rooms. Although I'm a beginner, I think to create a single chat room in SignalR is by this: <script type="text/javascript"> $(function () { var connection = $.connection.communicator; connection.receive = function (from, msg) { $("#chatWindow").append("<li>" + from + ": " + msg + "</li>"); }; $.connection.hub.start(); $("#btnSend").click

Implementing one to one and group chat in android [duplicate]

妖精的绣舞 提交于 2019-12-02 16:49:44
This question already has an answer here: How to make a chat application in android? [closed] 6 answers I am developing an Android app in which I have to implement chat messaging . I would like one to one chat or a group chat . But I have no idea how to start. Please help me with this stuff. Any help will be appreciated. A simple chat mechanism will have 2 basic functionalities Send the message to server (with info about the recipient) Receive the message from server (designated for my user name) First step is simple, we can create a web service which will accept the message with additional

running my own jabber/xmpp server [closed]

点点圈 提交于 2019-12-02 15:59:13
Can I make my own jabber server.So that if I run my website xyz then people should be be able to get their jabber id from my website by registering on my website. Is there any open source implementation of jabber server that I can use? I use Openfire to run my Jabber server and am quite happy with it. Probably higher-overhead than some of the other options (jabberd, ejabberd, etc.), but it's easy to install and has a great web-based admin UI. As far as adding users via a web application - I don't know how you would go about doing that with Openfire, but it should be possible. It can plug in to

How can I program a simple chat bot AI?

☆樱花仙子☆ 提交于 2019-12-02 13:58:10
I want to build a bot that asks someone a few simple questions and branches based on the answer. I realize parsing meaning from the human responses will be challenging, but how do you setup the program to deal with the "state" of the conversation? It will be a one-to-one conversation between a human and the bot. argv0 You probably want to look into Markov Chains as the basics for the bot AI. I wrote something a long time ago (the code to which I'm not proud of at all, and needs some mods to run on Python > 1.5) that may be a useful starting place for you: http://sourceforge.net/projects/benzo/