Closed GayanSamuditha closed 5 years ago
@GayanSamuditha , I don't know if it is exactly what do you want, but I have made a application a few months ago using SPADE 2 with Werkzeug on this link
Simply, how we run the SPADE server inside the Flask Server. OR how we connect we create agents and start agents in Flask web server
Note that in SPADE each agent has its own web server (uses aiohttp) so it is not easy to integrate into another application such as Flask. What you can do is change the port where the agent launches its web service (or even not launch it if you don't need it).
When you start the web of an agent you can choose the hostname and port:
agent.web.start(hostname="127.0.0.1", port="10000")
SPADE version: Latest One
Python version: multidict==4.4.0 aioxmpp>=0.10 aiohttp>=3.4.4 aiohttp_jinja2>=0.14.0 jinja2>=2.9.6 jinja2-time==0.2.0 timeago==1.0.8
Operating System: Windows 8.1
Description
I'm trying to integrate the spade code in flask application. While I add some code - DummyAgent with a web interface, in the flask application app.py, the flask application running on port 8080 and the spade is not working.
But I tried with DummyAgent without a web interface. It's working correctly
from flask import Flask, render_template from flask import redirect from urllib.parse import urljoin from flask_cdn import CDN from spade import agent
app = Flask(name)
@app.route('/') def hello_world(): return render_template("main.html")
class DummyAgent(agent.Agent): def setup(self): print("Hello World! I'm agent {}".format(str(self.jid)))
dummy = DummyAgent("agent1@GAYAN-SAMUDITHA", "agent1") dummy.start()
dummy.stop()
if name == 'main': app.run()
WITH WEB INTERFCE
from flask import Flask, render_template from flask import redirect from urllib.parse import urljoin from flask_cdn import CDN from spade import agent
app = Flask(name)
@app.route('/') def hello_world(): return render_template("main.html")
from spade import agent
class WebAgent(agent.Agent): def setup(self): print("Hello World! I'm agent {}".format(str(self.jid)))
dummy = WebAgent("admin@GAYAN-SAMUDITHA", "admin")
async def hello_controller(request): return {"number": 42}
a = WebAgent("agent1@GAYAN-SAMUDITHA", "agent1")
a.web.add_get("/hello", hello_controller, "hello.html")
a.start(auto_register=True) a.web.start(port=10000)
if name == 'main': app.run()
==> Not working