简体   繁体   English

如何在Chrome应用中创建简单的WebSocket服务器?

[英]How to create a simple WebSocket Server in Chrome App?

I'm trying to develop a Chrome App that will work together with a Chrome Extension that I already created, wherein the Chrome Extension will send information to the Chrome App. 我正在尝试开发一个可与我已经创建的Chrome扩展程序一起使用的Chrome应用程序,其中Chrome扩展程序会将信息发送到Chrome应用程序。

For this communication I thought use the WebSocket locally, in Chrome Extension I managed to make the Client, but now I'm having difficulty in creating the Server in the Chrome App, because I wanted to make as simple as possible without having to install something beyond of the Chrome App. 为了进行这种交流,我想在本地使用WebSocket,在Chrome扩展程序中我设法制作了客户端,但是现在我很难在Chrome应用中创建服务器,因为我想尽可能简单,而不必安装任何东西超越Chrome应用。

Among the first Google results there is a sample app from Chrome team: Http WebSocket Server . Google的第一批结果中有一个来自Chrome团队的示例应用程序: Http WebSocket Server

You've got to understand that making a server in Chrome Apps is difficult; 您必须了解在Chrome Apps中制作服务器非常困难; you are given access to a raw socket, and you need to fully implement the protocol that a particular server must use. 您将获得对原始套接字的访问权限,并且需要完全实现特定服务器必须使用的协议。 Even a HTTP server is non-trivial, WebSockets is even less so. 即使是HTTP服务器也不是一件容易的事,WebSockets甚至更是如此。

So: it's possible, but it's not simple unless you're using an existing library. 因此:这是可能的,但除非您使用现有的库,否则这并不简单。

Just to add to the accepted answer: 只是添加到接受的答案:

There is a Chrome Extension already in the Chrome Web Store: Web Server for Chrome . Chrome网上应用店中已经存在一个Chrome扩展程序: 适用于Chrome的Web服务器

And it is opensource: GitHub Link . 它是开源的: GitHub Link You can use it as a library to your Chrome App. 您可以将其用作Chrome应用程序的库。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM