java call网络编程底层,我可以用Java进行底层网络编程吗?

An application level message is send over the network in a series of packets that are assembled in the receiving side and passed to the application level.

Is it possible in Java to do network programming in the level of these individual packets?

Or in Java we can only see the "application" level packet? I.e. the "big-packet" that is assembled by all these network packets?

I tried to research on google for this matter but the results where really confusing.

The confusion is due to the fact that some resources that are about UDP seem to indicate that the operation is on packets, while others say that Java can not work in raw sockets which implies that it works on a higher level of abstraction.I could not find an answer to exactly what I am looking for.

If yes, which package does this?

解决方案

Is it possible in Java to do network programming in the level of these individual packets?

Yes, but it's very unlikely you would want individual packets.

Or in Java we can only see the "application" level packet?

Pure Java can only see TCP streams, and UDP datagram which have a one-to-one mapping with packets, but you have no access to the UDP header.

I.e. the "big-packet" that is assembled by all these network packets?

You don't get packets at all big or small. You read data and the data available is read (up to the size of your buffer)

If yes, which package does this?

You can use JPcap to see individual packets, however, this is rarely useful unless you need accurate time stamping of each packet or you need to trace dropped packets.

This uses winpcap (Windows) or libpcap (linux) via JNI.

In most of these cases where I have seen this used it was a lot of work for little gain.

from my point of view an answer mentioning JNI means that Java does not support it (since you have to actually code in another language for what you need)

Sockets, Files, GUI components all use JNI in the end. By this definition you can't do anything which uses a system call in Java, because the OS is not written in Java.

I don't think this is a useful definition of what you can do in Java.

1) Pure Java can only see TCP streams. What about UDP?

You don't have access to the packet's header with any protocol in Java without libPCap.

I assume this point means no packet access

Not without any additional libraries.

2) In most of these cases where I have seen this used it was a lot of work ? Why.

Because it is very low level and lots of details you don't normally have to worry about are exposed to you. Note: you might not get a packet as they can be dropped while attempting to record them and you won't be able to ask for them again so you miss them.

It is just a library right?

Correct.

Doesn't it work?

Why do you say that?

I am trying to see if what I need to do can be done in Java or should look into other languages.

IMHO, You won't find it any easier in another language.

I read in the jpcap docs that it can not reshape traffic e.g. drop packets etc. Why can't it do that?

You can't force a network to drop a packet and you can't trick the kernel in to drop one either. If you think about what a dropped packet is, the answer is fairly obvious.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值