473,320 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

UDP Client help

Hello,

I need help getting this accomplished. I think I'm close but I get confused because I'm a novice at java.
I'm trying to implement a ping client that accepts the hostname and the port. I have to send packets across with the following: PING, the sequence number which is the packet numbers 0-9, the time the packet was sent and CLRF. When each packet goes over it has to wait 1 sec for a reply.

Now one of my delimnas is (1) how do I get the time appeneded to my strings and (2) how do I wait 1 sec before I send another packet. Can someone help me to figure out how to implement what I'm trying to do?

This is what I have so far:

[code]
import java.io.*;
import java.net.*;
import java.util.*;
import java.net.InetAddress.*;


/*
* Client to process ping requests over UDP.
*/
public class PingClient
{
private static final double WAIT = 0.1;

public static void main(String[] args) throws Exception
{
// Get command line argument.Make sure host and port are intialized
if (args.length != 2) {
System.out.println("Required arguments: port, host, or both");
return;
}

int port = Integer.parseInt(args[1]);
String hostname = args[0];

// Create a datagram socket for receiving and sending UDP packets
// through the port specified on the command line.
DatagramSocket socket = new DatagramSocket(port);

//Invokes DNS lookup that translates the hostname to an IP address
InetAddress IPAddress = InetAddress.getByName("hostname");

//will hold the data the client sends and receives
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];

//Setting up packets message
String packet0 = "PING 0";
String packet1 = "PING 1";
String packet2 = "PING 2";
String packet3 = "PING 3";
String packet4 = "PING 4";
String packet5 = "PING 5";
String packet6 = "PING 6";
String packet7 = "PING 7";
String packet8 = "PING 8";
String packet9 = "PING 9";

//converts the string into bytes
sendpacket0 = packet0.getBytes();
sendpacket2 = packet1.getBytes();
sendpacket3 = packet1.getBytes();
sendpacket4 = packet1.getBytes();
sendpacket5 = packet1.getBytes();
sendpacket6 = packet1.getBytes();
sendpacket7 = packet1.getBytes();
sendpacket8 = packet1.getBytes();
sendpacket9 = packet1.getBytes();


// Create a datagram packet to send outgoing UDP packet.
DatagramPacket request0 = new DatagramPacket(sendpacket0, 1024, PortDayTime);
DatagramPacket request1 = new DatagramPacket(sendpacket1, 1024, PortDayTime);
DatagramPacket request2 = new DatagramPacket(sendpacket2, 1024, PortDayTime);
DatagramPacket request3 = new DatagramPacket(sendpacket3, 1024, PortDayTime);
DatagramPacket request4 = new DatagramPacket(sendpacket4, 1024, PortDayTime);
DatagramPacket request5 = new DatagramPacket(sendpacket5, 1024, PortDayTime);
DatagramPacket request6 = new DatagramPacket(sendpacket6, 1024, PortDayTime);
DatagramPacket request7 = new DatagramPacket(sendpacket7, 1024, PortDayTime);
DatagramPacket request8 = new DatagramPacket(sendpacket8, 1024, PortDayTime);
DatagramPacket request9 = new DatagramPacket(sendpacket9, 1024, PortDayTime);[code]
Mar 9 '08 #1
0 1143

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Justin Stockton | last post by:
I recently upgraded from ActivePython 2.2.2 to ActivePython 2.3.2 and I'm running into an issue importing the win32com.client module. Before installing the new version, I made sure to properly...
4
by: Arun Goel | last post by:
I have installed Oracle client & Oracle database(9.2.0.4) on Red Hat 9.0. It seems to me everything went fine in installation as I followed notes from...
6
by: Oliver Stratmann | last post by:
Hello All, we tried to set up a DB2-client for one customer. The situation was as follows: There are already DB2-Clients which are configured for the relevant DB2-databanse. We exported the...
0
by: Tim Northrup | last post by:
Help! We have DB2 V7.2 (fixpak 12) installed on Windows2003 Server, and the latest V7.2 client installed on another system. The DB2CODEPAGE on all systems is set to 1208, and the database was...
4
by: Yasaswi Pulavarti | last post by:
On an AIX server, I used the db2install script from the command line to install the DB2 UDB 8.1 client. I applied the fix pak 7 to it. Now I need to use the client to test connections to another...
11
by: Timothy Shih | last post by:
Hi, I am having a freezing issue with my application. My application serves several remotable objects, all of which must be initialized before their use. Furthermore, some of them depend on each...
0
by: Russ | last post by:
I have set up a C# web application that runs on my test Web Server (Windows 2003 Server, Web Edition). It in turn calls a web service running on the internal network. Now I want to issue a...
9
by: Harry Smith | last post by:
While reading the documentation on IsStartupScriptRegistered, there is a reference to "client startup script" as "Determines if the client startup script is registered with the Page object." What...
12
by: ShepardBerry | last post by:
This may be a dumb question, but I'm not finding anything specifically what I'm looking for. Still kind of new to .NET as well. What I'm trying to do that I know I could do in VB6.0/ASP is to...
0
by: 85ssp | last post by:
I am creating a small server client program that is meant for up to 70 connections from 70 different computers on a network. Everything in the program functions correctly except when testing...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.