我正在尝试使用flutter的计算方法在后台实现套接字连接。带有套接字的计算方法在Node.js本地服务器上工作,并成功地在后台发出所有事件。由于我托管了我的Node.js套接字服务器,客户端无法发出或侦听任何事件。我可以看到它已连接的日志,也可以记录套接字ID。我不确定这里出了什么问题。
BG方法调用
compute(DummyBG,DummyArgs(message:widget.arguments.message,sender_id:widget.arguments.user_id));
虚拟BG
Future forwardMessageBG(ForwardArgs args) async {
SocketUtils _socketUtils = SocketUtils();
await _socketUtils.initSocket(args.sender_id, args.user.user_id);
await _socketUtils.connect();
_socketUtils.socket.emit("message", [message.toJson()]);
}
SokcetUtils工具
class {
var user_id;
var recid;
initSocket(String user_id, String reciever_id) async {
user_id = user_id;
recid = reciever_id;
this._fromUser = user_id;
await _init();
}
_init() async {
socket = IO.io(
deployment ? _serverIP : SERVER_CHAT,
IO.OptionBuilder()
.enableForceNew()
.setTransports([
'websocket'
]) // for Flutter or Dart VM// disable auto-connection//
.setQuery({
"info": _fromUser,
})
.setPath(deployment ? "/chat" : "/socket.io")
.disableAutoConnect()
.build());
}
}
nginx配置如下。
server {
location / {
proxy_pass http://localhost:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade' ;
proxy_set_header Host Shost;
proxy_cache_bypass $http_upgrade;
}
location /chat/ {
proxy_pass http://localhost:3001/socket.io/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade' ;
proxy_set_header Host Shost;
proxy_cache_bypass $http_upgrade;
}
server_name api.axn.in; # managed by Certbot
proxy_read_timeout 600s; # added for user content upload
client_max_body_size 200m; # added for user content upload
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/api.axn.in/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/api.axn.in/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = api.axn.in) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name api.anx.in;
listen 80;
return 404; # managed by Certbot
}
当我与本地套接字服务器连接时,同样的代码工作得很好。
1条答案
按热度按时间nzkunb0c1#
你好,
不要忘记允许端口