| | |
How to set Timeout for DatagramConnection in J2ME
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2007
Posts: 22
Reputation:
Solved Threads: 0
Hai Friends, iam using udp connection for my project in j2me, its working fine, but i doknow how to set timeout for the Datagram connection. because there no server means it doesnot give exception.
my code is given below
my code is given below
public String UDP_Client(String str)
{
String UDP_RString="";
String UDP_Senddata = str;
DatagramConnection conn = null;
try {
String ServerAdd = "datagram://"+UDP_ServerIP+":"+UDP_ServerPort;
conn = (DatagramConnection)Connector.open(ServerAdd,Connector.READ_WRITE, false);
Datagram dg = conn.newDatagram(1000);
// String senddata = "JA_LGNDTLS 100002~100002~1.0.0ALPHA~No Mac Address~LINUXJAVA~ ~1111111111111111~23870BD7A92F6D~1~THEA,jaTHEA.BIL,19db6b53|~0";
dg.setData(UDP_Senddata.getBytes(), 0, UDP_Senddata.length());
conn.send(dg);
//conn.setTimeout(3000);
String Str="";
while (true)
{
Datagram rdg = conn.newDatagram(1000);
conn.receive(rdg);
if (rdg.getLength() > 0)
{
// si.setText("Message received - " + new String(dg.getData(), 0, dg.getLength()));
Str = (new String(rdg.getData(), 0, rdg.getLength()));
conn.close();
//conn.disconnect();
UDP_RString = Str;
}
}
}
catch (ConnectionNotFoundException cnfe )
{
System.out.println(cnfe);
UDP_RString = "*";
}
catch (Exception ex)
{
System.out.println(ex);
UDP_RString = "*";
}
System.out.println("out");
return UDP_RString;
} Last edited by Tekmaven; Jun 3rd, 2009 at 3:18 am. Reason: Code Tags
![]() |
Similar Threads
- how do i auto-shut down windows XP? (Windows NT / 2000 / XP)
- How to set timeout for reading from urls in urllib (Python)
- ReadFile function timeout ERROR (C++)
- Create timeout for Oracle DB connection attempt (Java)
- how i can set class path for j2me (Java)
- ASP Redirect on Session Timeout (ASP.NET)
- creating a set timeout for the Internet connection (Networking Hardware Configuration)
- RDS Issue in Internet Explorer (ASP)
Other Threads in the Java Forum
- Previous Thread: Unexpected Type/Incompatible Types
- Next Thread: Get rid of out of memory exception
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api append apple applet application arguments array arrays automation bi binary bluetooth businessintelligence busy_handler(null) chat class classes client code component database draw eclipse encryption equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop main map method methods mobile netbeans newbie number open-source oracle oriented panel print problem program programming project qt recursion reference replaysolutions repositories return robot scanner screen scrollbar se server set singleton size sms socket sort sql string swing test threads time tree utility windows xor





