javascript Thrift 客户端挂起 [英] javascript Thrift client hangs

查看:34
本文介绍了javascript Thrift 客户端挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 JavaScript 中有以下 Thrift 客户端代码:

I have the following Thrift client code in javascript:

<script language="javascript" type="text/javascript" src="thrift.js" />
<script language="javascript" type="text/javascript" src="QuantSvc_types.js" />
<script language="javascript" type="text/javascript" src="QuantSvc.js" />
<script language="javascript" type="text/javascript">
function calc() {   
    var transport = new Thrift.Transport("http://localhost:9997/QuantSvc/");   
    var protocol  = new Thrift.Protocol(transport);
    var client    = new QuantSvcClient(protocol);

    try {
        result = client.ListAllVariables()   
    } catch(ouch) {     
        alert("An exception occurred!")   
    } 
} 
</script>

当我按下 HTML 页面上的按钮时触发.然后,我有以下服务器端 Scala 代码,在 localhost:9997 上运行:

Which is triggered when I push a button on my HTML page. Then, I have the following server-side Scala code, running on localhost:9997:

object Application extends App {
    val handler = new QuantSvcHandler()
    val processor = new QuantSvc.Processor(handler)
    val serverTransport = new TServerSocket(9997)
    val server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor))    
}

QuantSvcHandler 的 ListAllVariables 函数在哪里(基本上是一个骨架函数,只是试图让事情工作):

Where the QuantSvcHandler's ListAllVariables function is (basically a skeleton function, just trying to get things to work):

override def ListAllVariables(): util.List[Attributes] =
{
  var input = scala.collection.mutable.Buffer[Attributes]()

  input
}

我在 ListAllVariables 的第一行以及 QuantSvcHandler 处理器中的几个地方放置了一个断点.我在 intellij IDEA 的调试中运行服务器,在 Chrome 中打开我的 HTML 页面,然后按下按钮(调用 javascript calc() 函数的那个​​).按钮卡住了,我在服务器上看不到任何响应,也没有点击断点.

I put a breakpoint at the first line of ListAllVariables, and also a few places in the QuantSvcHandler processor. I run the server in debug in intellij IDEA, open my HTML page in Chrome, and push the button (the one that calls the javascript calc() function). The button stays stuck and I see no kind of response on the server, the breakpoints aren't being hit.

对我做错了什么有任何想法吗?

Any ideas about what I'm doing wrong?

推荐答案

您将 HTTP 客户端与套接字服务器混合使用.

You mix a HTTP client with a socket server.

尽管 HTTP 使用套接字,但 Thrift HTTP 传输与 Thrift Sockets 传输不兼容.您需要在两端设置完全相同的协议/传输堆栈.该规则的唯一例外是某些服务器传输隐含地要求在客户端有一个额外的帧传输层.

Although HTTP uses sockets, the Thrift HTTP transport is not compatible with the Thrift Sockets transport. You need to set up the exact same protocol/transport stack on both ends. The only exception to that rule is that some server transports implicitly require an additional framed transport layer on the client side.

所以解决方案是使用 HTTP 服务器.根据您使用的版本,您可能还需要切换到 JSON 协议.

So the solution is to use a HTTP server. Depending on the version you use, you may also have to switch to the JSON protocol.

这篇关于javascript Thrift 客户端挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆