简体   繁体   English

在java中通过套接字发送链表

[英]Sending a linked list through socket in java

I want to send a linked list of objects through TCP socket from server to client, and vice-versa. 我想通过TCP套接字从服务器向客户端发送对象的链接列表,反之亦然。 How can I do that? 我怎样才能做到这一点? Should I send just a head of linked list, or is there some other way? 我应该只发送一个链表头,还是有其他方式?

Use LinkedList<T> which is Serializable . 使用LinkedList<T>这是Serializable

EDIT The T must implement the Serializable interface which has no method - This just a marker. 编辑T必须实现没有方法的Serializable接口 - 这只是一个标记。 Your class may have some fields that are not essential to the object (for instance, a cached value computed from actual properties of the object), these can be declared as transient . 您的类可能有一些对象不重要的字段(例如,根据对象的实际属性计算的缓存值),这些可以声明为transient
Have a look at the doc of Serializable . 看看Serializable的文档

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

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