简体   繁体   English

TCP-JAVA客户端和C服务器发送和接收对象/结构

[英]TCP - JAVA Client and C Server Sending and receiving objects/structures

A chat application was successfully implemented between C Server and Java client using TCP-IP. 使用TCP-IP在C服务器和Java客户端之间成功实现了聊天应用程序。 Now I want to send objects to C Server which will receive them as structures. 现在,我想将对象发送到C Server,后者将以结构形式接收它们。 I used ObjectStreams for this but I understand that fails because the other end doesn't have ObjectStreams. 我为此使用了ObjectStreams,但是我知道失败了,因为另一端没有ObjectStreams。 So how do I go about it? 那我该怎么办呢? A detailed step by step example or tutorial would be appreciated. 详细的分步示例或教程将不胜感激。 Thanks in advance! 提前致谢!

As I keep saying in comments on other questions, don't use structs as protocols. 正如我在其他问题的评论中经常说的那样,请勿将结构用作协议。 Design yourself a wire protocol in terms of octets, then write yourself an API to send and receive it. 根据八位字节设计一个有线协议,然后为自己编写一个API以发送和接收它。 Extend the API to handle the Java classes/C structs you want to handle. 扩展API以处理您要处理的Java类/ C结构。 Use DataInput/OutputStream at the Java end and make sure to make proper use of ntohl() and friends at the C end. 在Java端使用DataInput/OutputStream ,并确保在C端正确使用ntohl()和朋友。

Or, save yourself a lot of bother and use XML or SOAP. 或者,省去很多麻烦,并使用XML或SOAP。

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

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