简体   繁体   中英

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. Now I want to send objects to C Server which will receive them as structures. I used ObjectStreams for this but I understand that fails because the other end doesn't have 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. Extend the API to handle the Java classes/C structs you want to handle. Use DataInput/OutputStream at the Java end and make sure to make proper use of ntohl() and friends at the C end.

Or, save yourself a lot of bother and use XML or SOAP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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