Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-09-2008, 08:31 PM
Member
 
Join Date: Mar 2008
Posts: 1
misslilbit02 is on a distinguished road
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);
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Client IP Address goodjonx Networking 2 01-12-2008 12:08 PM
Identify Client in Socket Client Server Application masadjie Networking 1 12-20-2007 10:18 AM
Client TCP in Java baltimore Networking 3 08-09-2007 09:18 PM
ThinkUI SQL Client 1.0.1 levent Java Announcements 0 07-26-2007 09:18 PM
client for PERFORCE Ed New To Java 2 07-02-2007 08:30 PM


All times are GMT +3. The time now is 08:27 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org