DatagramSocket! I am getting IllegalArgumentException but can't figure out why.



Dear All,

I am new to Socket Programming. I am trying to send data using UDP but
I get the IllegalArgument Exception but I can't find why I am getting
this exception.
The program below is implemented on server.Which recieves the packet
from the Client and then reads its port number and address and sends
the DATE back to the Client.I am using getBytes() method to convert
data to bytes[] and this line gives the error. Whenever I comment this
line there is no Exception and Client recieves an empty message. Can
anybody figure out where is the problem.

int length=1024;
byte[] buf=new byte[length];
byte[] data= new byte[length];
int visit=1;
try {
DatagramSocket listener = new DatagramSocket(port);
//Socket serverSocketAccepted;
DatagramPacket packet= new DatagramPacket(buf,length);
while(true)
{
listener.receive(packet);
InetAddress clientAddr = packet.getAddress();
int clientPort = packet.getPort();


// Here I will read the data

long time =
System.currentTimeMillis();
Date d= new Date(time);
String date=d.toString();
--------------> data=date.getBytes(); // When this line is
absent there is no Exception

DatagramPacket packetSend= new
DatagramPacket(data,length,clientAddr,clientPort);


listener.send(packetSend);
}


Thanks,
Aamir

.



Relevant Pages

  • Re: Client Firewall and Outlook
    ... Additionally there are times when a user is on the phone to a client, ... I am trying to add Outlook ... as an exception to the firewall list. ... on windows firewall in control panel. ...
    (microsoft.public.windows.server.sbs)
  • Re: Code design ideas?
    ... app and the webservice, etc. ... Errors of type 1 should be handled by the client side. ... Usually it is the Message of the Exception. ... severity levels: warning and error. ...
    (microsoft.public.dotnet.languages.csharp)
  • Assmebly.Load error using Byte()
    ... I have 2 WebApplication project (dummy and dummy2). ... The first is trying to load a UserControl compiled in the second. ... The web sites are formed of a client part and an administration part. ... An unhandled exception occurred during compilation using ...
    (microsoft.public.dotnet.framework.aspnet)
  • friendly error messages for usernameForCertificateSecurity
    ... returned to the client in a simple way. ... In the code above if I comment out the throwing of the soap exception on the ... "Security requirements are not satisfied because the security header is not ... true error message is a less then desireable solution. ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • Re: friendly error messages for usernameForCertificateSecurity
    ... You are receiving that security error because WSE could not validate the ... The WSE core is who creates that exception, and it does not provide a way ... a.You can maybe use a WSE router between the client and the service, ...
    (microsoft.public.dotnet.framework.webservices.enhancements)