Android okhttp:创建WebSocketCall无法正常工作

时间:2016-08-06 13:28:59

标签: java android okhttp wss android-webservice

所以我想弄清楚如何为我的Android应用程序建立wss连接,这就是我现在面临的问题:

这是我的ApiConnection课程:

var http = require('http');
var url = require('url');
var path = require('path');
var fs = require('fs');
var port = 8080;

var appMainFileName = "app.html";
var mimeTypes = {
    "html": "text/html",
    "jpeg": "image/jpeg",
    "jpg": "image/jpeg",
    "png": "image/png",
    "js": "application/javascript",
    "css": "text/css"
};

http.createServer(function(request, response) {

  var uri = url.parse(request.url).pathname,
    fileName = path.join(process.cwd(), uri);       

  fs.exists(fileName, function(exists) {
    if (!exists) {
      response.writeHead(404, {"Content-Type": "text/plain"});
      response.write("404 Not Found\n");
      response.end();
      return;
    }

    if (fs.statSync(fileName).isDirectory()) {
            fileName += '/' + appMainFileName;
        }

    fs.readFile(fileName, "binary", function(err, data) {
      if (err) {        
        response.writeHead(500, {"Content-Type": "text/plain"});
        response.write(err + "\n");
        response.end();
        return;
      }

      response.writeHead(200, {"Content-Type": mimeTypes[ fileName.split(".")[1] ]});
      response.write(data, "binary");
      response.end();
    });
  });


}).listen(port);

我面临的问题是在此行之后没有执行任何操作: WebSocketCall call = WebSocketCall.create(client,request);

所以,“HELLO WORLD”从未打印过。并且“onOpen”,“onFailure”等方法都没有贯穿其中。这使得无法使用来自服务器的响应。 这段代码出了什么问题?我该如何解决这个问题?

PS我对此非常陌生,所以如果其他地方有点奇怪,请告诉我。)

谢谢:)

0 个答案:

没有答案