How can I ping an IP address using a socket program and send data through it?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- Multiple sockets for clients to connect to
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
You can't do ping in Java -- ping works at ICMP level which works on top of IP, whereas Java offers support for UDP (which sits on top of IP) and TCP (again on top of IP). It's basically a different (higher level) protocol for which you will need your own (native) library written in order to gain access to the IP stack.
Ping is a specific ICMP protocol. You cannot send ICMP packets in pure Java.
However, you can open a TCP Socket to a specific port and send it some data. There are millions of example of tutorials on how to do this.
I suggest you look at these
http://www.google.co.uk/search?q=java+socket+tutorial 6 million results
http://www.google.co.uk/search?q=java+socket+example 11.6 million results.
To send just one character you can do
Ping uses ICMP protocol that is not available in java. This can be a better way to ping a server in java is to :
}
Also another way could be is to work with pure java sockets.