在Appengine上可以使用套接字(sockets)而无需特殊的库吗?

huangapple go评论86阅读模式
英文:

Can I use sockets on Appengine without a special lib?

问题

我对GAE的文档感到困惑。它说“App Engine支持套接字,无需导入任何特殊的App Engine库或添加任何特殊的App Engine代码”,但是它似乎有误导性,因为在上面它说“App Engine通过appengine/socket包支持出站套接字”。

我想使用标准的net包连接到一个IMAP服务器。这是否可能,还是我必须使用GAE的套接字API?

英文:

I'm confused by the GAE documentations. It says App Engine supports sockets without requiring you to import any special App Engine libraries or add any special App Engine code. but it seems misleading as just above it says App Engine supports outbound sockets through the appengine/socket package.

I would like to connect to an IMAP server using the standard net package. Is that possible or I'm stuck with the GAE sockets API?

https://cloud.google.com/appengine/docs/go/sockets/

答案1

得分: 2

不经过appengine/socket api,无法打开出站套接字。这是因为它通过RPC工作,需要一个appengine.Context来完成。不过,你仍然可以使用你提供的IMAP库,因为它提供了一个使用给定net.Conn创建客户端的函数。你可以从appengine/socket获取一个net.Conn,并将其传递给NewClient来进行操作。之所以在Python和Java上可以工作,是因为它们都使用线程本地内存来隐式管理请求状态,而Go运行时不支持这一点。

英文:

It is not possible to open an outbound socket without going through the appengine/socket api. This is because it works through RPC and an appengine.Context is needed to do that. You can still use the IMAP library you linked, though, as it provides a function to create a client with a given net.Conn. You can get a net.Conn from appengine/socket and pass it to NewClient to do your business. The reason it works on python and java is because they both use thread local memory to manage request state implicitly, whereas the go runtime does not.

答案2

得分: 1

没有什么能阻止你连接到一个IMAP服务器,因为你将发起一个出站连接。对于Java来说,标准的Java邮件包可以直接使用。
只有对于付费应用程序,也就是说,你需要启用计费功能。

英文:

Nothing stops you from connecting to an Imap server, since you will initiate an outbound connection. For java, the standard java mail packages work out of the box.
Only for paid apps though, i.e. you need to have billing enabled.

huangapple
  • 本文由 发表于 2014年10月26日 21:39:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/26573597.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定