Results 1 to 4 of 4
Thread: Ping Client error - help. =]
- 02-14-2009, 05:41 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
Ping Client error - help. =]
Hi, I am writing a UDP ping client program. I am using a function called PingMessage, however I keep getting compile errors that say:
"cannot find symbol
symbol: class PingMessage"
Maybe I am overlooking something small... I was up all night coding this.
Thanks in advance for any help!
Code here:
Java Code:import java.io.*; import java.net.*; import java.lang.Object; import java.util.*; import java.net.InetAddress.*; public class PingClient implements Runnable { String hostname; int portnumber; int pingReplies = 0; static final int pingLength = 1024; static final int PINGS = 10; static final int TIMEOUT = 1000; static final int WAIT = 5000; /* Arrays */ static boolean[] replies = new boolean[PINGS]; static long[] RTT = new long[PINGS]; DatagramSocket socket; public PingMessage receivePing() throws SocketTimeoutException { byte recvBuf[] = new byte[pingLength]; DatagramPacket recvPacket = new DatagramPacket(recvBuf, pingLength); PingMessage reply = null; try { socket.receive(recvPacket); System.out.println("Received message from " + recvPacket.getAddress() + ":" + recvPacket.getPort()); String recvMsg = new String(recvPacket.getData()); reply = new PingMessage(recvPacket.getAddress(), recvPacket.getPort(), recvMsg); } catch (SocketTimeoutException e) { throw e; } catch (IOException e) { System.out.println("Error reading from socket."); } return reply; } public void sendPing(PingMessage ping) { InetAddress host = ping.getHost(); int port = ping.getPort(); String message = ping.getContents(); DatagramPacket packet = new DatagramPacket(message.getBytes(), message.length(), host, port); socket.send(packet); System.out.println("Sent packet to " + host + ":" + port); } private void handleReply(String reply) { String[] tmp = reply.split(" "); int pingNumber = Integer.parseInt(tmp[1]); long then = Long.parseLong(tmp[2]); replies[pingNumber] = true; Date now = new Date(); RTT[pingNumber] = now.getTime() - then; pingReplies++; } public PingClient (String host, int port) { hostname = host; portnumber = port; } public void createSocket() { try { socket = new DatagramSocket(); } catch (SocketException e) { System.out.println("Error creating socket."); } } public void createSocket(int port) { try { socket = new DatagramSocket(port); } catch (SocketException e) { System.out.println("Error creating socket."); } } /*-----------------------------------------------------------*/ public void run() { createSocket(); socket.setSoTimeout(TIMEOUT); for (int i = 0; i < PINGS; i++) { Date now = new Date(); String message = "PING " + i + " " + now.getTime() + " "; replies[i] = false; RTT[i] = 1000000; PingMessage ping = null; } ping = new PingMessage(InetAddress.getByName(hostname), portnumber, message); sendPing(ping); PingMessage reply = receivePing(); handleReply(reply.getContents()); try { socket.setSoTimeout(WAIT); } catch (SocketTimeoutException e) { System.out.println("Error setting timeout REPLY_TIMEOUT: "); } while (pingReplies < PINGS) { try { PingMessage reply = receivePing(); handleReply(reply.getContents()); } catch (SocketTimeoutException e) { pingReplies = PINGS; } } for (int i = 0; i < PINGS; i++) { System.out.println("PING " + i + ": " + replies[i] + " RTT: " + RTT[i]); } } /*----------------------------------------------------------------*/ public static void main(String args[]) { String host = null; int port = 0; host = args[0]; port = Integer.parseInt(args[1]); System.out.println("Contacting host " + host + " at port " + port); PingClient Client = new PingClient(host, port); Client.run(); } }
- 02-14-2009, 10:15 PM #2
PingMessage class?
huh... I don't see a PingMessage class. I only see a PingClient class... does PingMessage.class exist?
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-15-2009, 02:29 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
I am getting the error from the function:
public PingMessage receivePing()
Am I using that correctly?
- 02-18-2009, 02:57 PM #4
Similar Threads
-
Ping in Java
By VeasMKII in forum New To JavaReplies: 7Last Post: 10-14-2012, 09:51 PM -
Ping pong game
By adam405 in forum New To JavaReplies: 8Last Post: 10-20-2010, 03:52 PM -
How to mesure ping delay in JAVA..?
By sacr83 in forum NetworkingReplies: 4Last Post: 06-15-2008, 06:37 AM -
How to write a JAVA program to mesure ping delay..?
By sacr83 in forum NetworkingReplies: 1Last Post: 02-15-2008, 04:07 PM -
ping cmd
By kishi in forum Advanced JavaReplies: 2Last Post: 11-14-2007, 03:27 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks