I am pretty new to java socket programming. I had already gone thorugh that java only deals with Internet Domain Sockets and it will support UDP and TCP and Raw IP Protocols. I want to know that is java support Raw Sockets without using any third party applications? If it is possible can anyone help me with a small example? Any small advice will be very greatful!
Asked
Active
Viewed 2.0k times
10
-
1if you want the source code on how java implements socket then take a look a the source code http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/net/Socket.java – AurA Feb 14 '13 at 11:05
-
1is java support row socket? – Nikhil Feb 14 '13 at 11:11
-
5TCP/IP and UDP are not raw sockets. – Audrius Meškauskas Feb 14 '13 at 11:14
-
2@duffymo The JDK/JRE do not support raw sockets. – user207421 Feb 14 '13 at 11:15
-
@AudriusMeškauskas That i know. But it supports Raw IP protocol. Is it? – Nikhil Feb 14 '13 at 11:18
-
If you mean TCP/IP (and not HTTP, FTP, etc), then yes. java.net.Socket and java.net.ServerSocket. – Audrius Meškauskas Feb 14 '13 at 11:20
-
Do you really need "raw" sockets? Then see [this question](http://stackoverflow.com/questions/11536232/how-to-open-layer-2-raw-sockets-in-java). Perhaps you just want to send data over TCP where a "regular" socket would be a better fit. Anyhow show what you have tried and found. – CodeCaster Feb 14 '13 at 11:25
-
2possible duplicate of [Best way to do RAW socket programming involving Java](http://stackoverflow.com/questions/3854961/best-way-to-do-raw-socket-programming-involving-java) – Stephen C Feb 14 '13 at 11:38
1 Answers
5
The only really available support for raw sockets in Java standard library seems the InetAddress.isReachable() that may do ICMP ping if permitted. This is really not much and probably even not really a raw socket, just one more protocol.
For other types of raw communication I would recommend to use Berkley sockets under Linux (root rights required) through some JNI - based wrapper.

Audrius Meškauskas
- 20,936
- 12
- 75
- 93
-
See Comments to original post. All the "java.net" interface supports Berkley sockets protocols and is implemented inside the JVM. – James Anderson Feb 14 '13 at 11:19
-
2"Raw sockets" in understand something that is capable of writing fully custom network packets, supporting things like arbitrary (not just ping) ICMP requests. – Audrius Meškauskas Feb 14 '13 at 11:25
-
3@JamesAnderson - your comment doesn't make any sense. 1) Berkeley sockets is an API not a protocol. 2) While the JVM may (or may not) use those C/C++ APIs internally, they are NOT directly available to Java code. – Stephen C Feb 14 '13 at 11:35