View Single Post
  #1 (permalink)  
Old 03-28-2008, 05:12 PM
markyoung1984 markyoung1984 is offline
Member
 
Join Date: Mar 2008
Posts: 3
markyoung1984 is on a distinguished road
My thread will not start
I have my thread class (which transmits a datagram):

Code:
public class heartbeat extends Thread { private int portNum; private InetAddress address; private int siteNum; public heartbeat(InetAddress pAddress, int pPortNum, int pSiteNum) { portNum = 3001; address = pAddress; siteNum = pSiteNum; } public void Run() { byte[] buf = new byte[256]; String stringToSend = "[H," + siteNum + "]"; buf = stringToSend.getBytes(); System.out.println("Port is " + portNum); try { DatagramSocket socket = new DatagramSocket(portNum); DatagramPacket packet = new DatagramPacket(buf, buf.length, address, portNum); while(true) { System.out.println(stringToSend); socket.send(packet); } } catch (Exception e) { System.exit(0); } } }
and then the following two lines in my main program.

Code:
heartbeat myHeartbeat = new heartbeat(serverAddr, serverPort, siteID); myHeartbeat.start();
It all looks right to me but the thread will not run and I can't see whats wrong with it!! Please help.
Reply With Quote
Sponsored Links