简体   繁体   English

是否有一个TCP套接字库/协议可以进行消息成帧,并且在JS&C#中受支持?

[英]Is there a TCP Socket Library/Protocol that does message framing and is supported in JS & C#?

I'm in the process of building an application that requires clients to exchange messages between each other (similar to chat) using a server. 我正在构建一个应用程序,要求客户端使用服务器在彼此之间交换消息(类似于聊天)。

I want to write the server in JavaScript using Node JS, the client applications are written in C#.NET. 我想使用Node JS用JavaScript编写服务器,客户端应用程序用C#.NET编写。

I've researched for a while and discarded Socket.IO due to the lack of C# support and because I'm looking for something more low-level and flexible/customizable. 由于缺乏C#支持并且我正在寻找更底层,更灵活/更可定制的东西,因此我已经研究了一段时间并丢弃了Socket.IO。

I'm written once an application very similar which used the built in NodeJS 'net' module as the server and the C# TCPClient client-side, it works, but it uses a stream and I have to prefix the message length before each message. 我曾经写过一个非常相似的应用程序,它使用内置的NodeJS'net'模块作为服务器和C#TCPClient客户端,它可以工作,但是它使用流,并且我必须在每个消息之前给消息长度加上前缀。

I'm looking for something more redundant that has message framing out-of-the-box and is supported by the languages I'm using. 我正在寻找一些多余的东西,它们具有开箱即用的消息框架,并且受我使用的语言支持。

I've found the 'ws' (WebSocket) npm module which seems like a promising candidate, especially since it might go along well with the C# Socket class (which is also the underlying socket used by the TCPistener and TCPClient classes) but for the life of me I can't figure out if I'll still have to expect a Socket Stream or just set an event handler for new message events. 我发现'ws'(WebSocket)npm模块似乎是一个有前途的候选对象,特别是因为它可能与C#Socket类(它也是TCPistener和TCPClient类使用的基础套接字)配合得很好。我的生活我无法弄清楚我是否仍然需要期待Socket流或只是为新消息事件设置事件处理程序。

I'm looking for something that's really simple to implement and will notify for each message I receive so I can handle it, no matter the size of the message or buffer (I plan to send average messages a megabyte in size...), I never want to handle the buffer, and of course it should be well supported in the above languages. 我正在寻找一种非常易于实现的东西,并且会针对收到的每条消息进行通知,因此无论消息或缓冲区的大小如何(无论我打算发送平均大小为兆字节的消息……),我都可以对其进行处理,我从来不想处理该缓冲区,当然上述语言应该很好地支持它。

WebSockets already work with messages, you don't need to prefix the size, just hook to the message event and it will be received complete. WebSockets已经可以处理消息了,您不需要添加大小前缀,只需挂接到消息事件就可以了。

I personally use websocket-sharp because it's portable and works perfectly under mono/linux, but if your target is just Windows yo can use the integrated .net websockets: https://msdn.microsoft.com/es-es/library/system.net.websockets.websocket(v=vs.110).aspx 我个人使用websocket-sharp,因为它可移植并且可以在mono / linux下完美运行,但是如果您的目标是Windows,则可以使用集成的.net websockets: https ://msdn.microsoft.com/es-es/library/system .net.websockets.websocket(v = vs.110).aspx

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

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