简体   繁体   English

用Java读写TCP标头(选项)

[英]Reading and writing TCP header (options) in Java

What I'm trying to do is: Writing client and server for sending a String via TCP with Java, so far no problem using Socket and Input-/Output-Streams. 我正在尝试做的是:编写客户端和服务器以使用Java通过TCP发送字符串,到目前为止,使用套接字和输入/输出流没有问题。

But now I'm trying to add 3 numbers to the "Options" field in the tcp header 但是现在我试图将3个数字添加到tcp标头中的“选项”字段中 在此处输入图片说明 . I can't find any helpful tutorials or something else on how to customize the header and how to read it. 我找不到任何有用的教程或其他有关如何自定义标题和如何阅读标题的内容。

Any suggestions? 有什么建议么?

You can't: 您不能:

  • at application level, you do not have access to the TCP headers; 在应用程序级别,您无权访问TCP标头;
  • Java does not have raw sockets either. Java也没有原始套接字。

You can somewhat influence some of the TCP behavior by setting different socket options, though. 通过设置不同的套接字选项,您可以在某种程度上影响某些 TCP行为。 But not manipulating TCP headers directly. 但不能直接操作TCP标头。

Not without utilizing external library like jNetPcap. 并非没有利用jNetPcap之类的外部库。 jNetPcap does allow you to format and send your own packet. jNetPcap允许您格式化和发送自己的数据包。

jNetPcap Installation Guide (Eclipse) jNetPcap安装指南(Eclipse)

jNetPcap Installation Guide (NetBeans) jNetPcap安装指南(NetBeans)

A very rough sample code for formatting and sending packet . 用于格式化和发送数据包的非常粗糙的示例代码。 Rough it may be, but it shows you the possibilities to customize the packet. 可能很粗糙,但是它向您展示了定制数据包的可能性。

Edit: Forgot to mention that jNetPcap is a Java wrapper for libpcap. 编辑:忘记提及jNetPcap是libpcap的Java包装器。 They are meant to be utilized to read the packet in the first place. 首先是要使用它们来读取数据包。

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

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