简体   繁体   English

如何做Java tcp客户端< - > Qt tcp服务器套接字通信

[英]How to do Java tcp client <-> Qt tcp server socket communication

What I want to know is if this is a good way to do this, or if there's another better and optimal one. 我想知道的是,这是一个很好的方法,或者是否有另一个更好和最佳的方法。 (This is for a local network only, not Internet) (这仅适用于本地网络,不适用于Internet)

I'm trying to implement a communication system between a tcp server (written in Qt in windows) and a tcp client (written in java in android) using sockets. 我正在尝试使用套接字在tcp 服务器 (用Windows编写的Qt )和tcp 客户端 (用android编写的java )之间实现通信系统。 This is 这是

I need to basically do two things: transfer files, and transfer some data. 我需要基本上做两件事:传输文件,并传输一些数据。

  • So, I've decided to use a string based communication method to handle the custom protocol. 所以,我决定使用基于字符串的通信方法来处理自定义协议。

  • For the data transfer, I've tought to create a xml file with the data (convert the collections to xml markers and set its values), send the file, and then parse it in the other point. 对于数据传输,我已经尝试使用数据创建一个xml文件(将集合转换为xml标记并设置其值),发送文件,然后在另一点解析它。

I have not much knowledge in network programming so please give me a hand on this. 我对网络编程知之甚少,所以请帮我解决一下。 Thank you. 谢谢。

I made 2 simple client applications using the socket communication for my exams. 我为我的考试使用套接字通信制作了两个简单的客户端应用程序。 They both communicate with a Java server, one of them is an android application, the second one is a Qt application (this one should help you as you want to know how to make your Java app communicate with Qt). 它们都与Java服务器通信,其中一个是android应用程序,第二个是Qt应用程序(这个应该帮助你,因为你想知道如何让你的Java应用程序与Qt通信)。 You can download these 3 applications here . 您可以在此处下载这3个应用程序。 Excuse me if some comments have been made in French, I use to code in English but I'm facing a French jury :P. 对不起,如果用法语做了一些评论,我用英语编码,但我面对法国陪审团:P。 Take a deep look to NetworkUtil::receiveString(QDataStream &in) method in the Qt application. 深入了解Qt应用程序中的NetworkUtil :: receiveString(QDataStream&in)方法。 Also always use qint32 to receive int from the Java application. 也总是使用qint32从Java应用程序接收int。 If you need further explanations please let me know. 如果您需要进一步说明,请告诉我。 E-Kami E-卡米

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

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