简体   繁体   English

使用套接字将VB.NET前端与Python后端连接是一个好主意还是一个坏主意?

[英]Would it be a good idea or bad idea to connect a VB.NET frontend with a Python backend using sockets?

I have some really nice Python code to do what I need to do. 我有一些非常不错的Python代码来完成我需要做的事情。 I don't particularly like any of the Python GUI choices though. 我不特别喜欢任何Python GUI选项。 wxPython is nice, but for what I need, the speed on resizing, refreshing and dynamically adding controls just isn't there. wxPython很不错,但是对于我所需要的,调整大小,刷新和动态添加控件的速度还不存在。 I would like to create the GUI in VB.NET. 我想在VB.NET中创建GUI。 I imagine I could use IronPython to link the two, but that creates a dependency on a rather large third-party product. 我想我可以使用IronPython来链接两者,但这会创建对相当大的第三方产品的依赖。 I was perusing the MSDN documentation on Windows IPC and got the idea to use sockets. 我仔细阅读了Windows IPC上的MSDN文档,并有了使用套接字的想法。 I copied the Python echo server code from the Python documentation and in under 5 minutes was able to create a client in VB.NET without even reading the System.Net.Sockets documentation, so this certainly doesn't seem too hard. 我从Python文档中复制了Python回显服务器代码,并且不到5分钟就可以在VB.NET中创建客户端,而无需阅读System.Net.Sockets文档,因此这看起来似乎并不难。

The question I have is... is this a terrible idea? 我的问题是...这是一个可怕的主意吗? If so, what should I be doing instead? 如果是这样,我应该怎么做?

If this is a good idea, how do I go about it? 如果这是个好主意,我该怎么做?

It's not a terrible idea. 这不是一个糟糕的主意。 In fact, if you write the Python code to have a RESTful interface, and then access that from VB.NET, it is a downright good idea. 实际上,如果您编写Python代码以具有RESTful接口,然后从VB.NET访问该接口,则这是个好主意。 Later on you could reuse that Python server from any other application written in Python or VB.NET or something else. 稍后,您可以从任何其他用Python或VB.NET或其他语言编写的应用程序中重用该Python服务器。 Because REST is standard and easy to test, people can even do GETs from a browser and maybe that will be useful in itself. 因为REST是标准的并且易于测试,所以人们甚至可以通过浏览器执行GET,也许它本身会很有用。

Here is a Yahoo page that gives you code examples to do REST GET, POST and so on, in VB.NET . 这是一个Yahoo页面,为您提供在VB.NET中执行REST GET,POST等的代码示例

If you think REST has too much overhead and need something more lightweight, please don't try to invent your own protocol. 如果您认为REST的开销太大,并且需要更轻量的东西,请不要尝试发明自己的协议。 Consider something like Google's Protocol Buffers which can also be used from VB.NET . 考虑类似Google的协议缓冲区之东西,也可以在VB.NET中使用它

I think this is an excellent idea. 我认为这是个好主意。 I'll second Michael Dillon's recommendation for a REST API, and I'll further recommend that you use Django to implement your REST server. 我将第二次推荐Michael Dillon对REST API的建议,并进一步建议您使用Django来实现REST服务器。

I wrote a REST web service using Django, and Django made it really easy and fun. 我使用Django编写了一个REST Web服务,而Django使它变得非常容易和有趣。 Django made it really simple to set up the URLs the way I wanted them, to run whatever code a URL called for, and to interact with the database as needed. Django使按照我想要的方式设置URL,运行URL要求的任何代码以及根据需要与数据库进行交互的过程非常简单。 My web service was rock solid reliable, and I was able to test it for debugging simply using a web browser. 我的Web服务非常可靠,我可以使用Web浏览器对其进行调试测试。

If you already have your code working in Python and just want to slap on a glue interface, and if REST doesn't seem like what you want, you could look at the Twisted networking framework. 如果您已经有使用Python编写的代码,并且只想在粘合界面上拍打,并且如果REST看起来不是您想要的,则可以查看Twisted网络框架。 Here is a nice article on how to do networking in Python with both the standard Python modules and with Twisted. 是一篇很好的文章,介绍了如何在Python中使用标准Python模块和Twisted进行联网。

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

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