I am supposed to have a system that takes data from a packet and does things with it. I had some code that was working fine, I made a few changes involving trying to get the instruction portion of the data out (the first 5 characters) and the code stops whenever the string "message" is initialised about halfway down. There are no errors or anything, the debugger just highlights the word "string" on that line and then just stops.
I've been playing around with it, and it seems no matter what the situation whenver I initialise a second string in the program, the debugger highlights the last keyword in that line and then just stops. I'll post the current code below, then below that code from an earlier version which was working fine.
Appreciate any help!
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package reservationsystemserver; import java.io.*; import java.net.*; import java.util.*; /** * * @author Norman */ public class serverActions implements Runnable { DatagramPacket packet = null; InetAddress returnIP = null; int returnPort = 0; public serverActions(DatagramPacket packet) { this.packet = packet; this.returnIP = packet.getAddress(); this.returnPort = packet.getPort(); } public void run() { DatagramPacket packet2; packet2 = packet; if (parseInstruction(packet).equals("LOGIN")) { login(packet2); } } private void login(DatagramPacket packet) { try { String instructionType, username; int loopBreak = 0; String message = new String(packet.getData(),0,packet.getLength()); System.out.println(packet.getSocketAddress()); StringTokenizer st = new StringTokenizer(message,"."); instructionType = st.nextToken(); username = st.nextToken(); System.out.println(instructionType); System.out.println(username); System.out.println("Printed"); File file = new File("C:\\Users\\Norman\\Documents\\NetBeansProjects\\ReservationSystemServer\\loggedInUsers.txt"); while (loopBreak == 0) { if (file.canWrite()) { BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\Norman\\Documents\\NetBeansProjects\\ReservationSystemServer\\loggedInUsers.txt")); String[] loggedInUsers = new String[1000]; int i = 0; String value = br.readLine(); while (value != null) { loggedInUsers[i] = value; i++; value = br.readLine(); } Writer output = null; String eol = System.getProperty("line.separator"); output = new BufferedWriter(new FileWriter(file)); output.write(username); output.write(" Has logged in from "); output.write(returnIP.toString()); i = 0; while (loggedInUsers[i] != null) { output.write(eol + loggedInUsers[i]); i++; } output.close(); loopBreak = 1; } } } catch (IOException e){ System.out.println(e.getMessage()); } } private String parseInstruction(DatagramPacket packet) { String stringg = new String(packet.getData(),0,packet.getLength()); StringTokenizer tf = new StringTokenizer(stringg,"."); String instructionType = new String(tf.nextToken()); return instructionType; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package reservationsystemserver; import java.io.*; import java.net.*; import java.util.*; /** * * @author Norman */ public class serverActions implements Runnable { DatagramPacket packet = null; InetAddress returnIP = null; int returnPort = 0; public serverActions(DatagramPacket packet) { this.packet = packet; this.returnIP = packet.getAddress(); this.returnPort = packet.getPort(); } public void run() { try { String message, instructionType, username; int loopBreak = 0; message = new String(packet.getData(),0,packet.getLength()); System.out.println(packet.getSocketAddress()); StringTokenizer st = new StringTokenizer(message,"."); instructionType = st.nextToken(); username = st.nextToken(); System.out.println(instructionType); System.out.println(username); System.out.println("Printed"); File file = new File("C:\\Users\\Norman\\Documents\\NetBeansProjects\\ReservationSystemServer\\loggedInUsers.txt"); while (loopBreak == 0) { if (file.canWrite()) { BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\Norman\\Documents\\NetBeansProjects\\ReservationSystemServer\\loggedInUsers.txt")); String[] loggedInUsers = new String[1000]; int i = 0; String value = br.readLine(); while (value != null) { loggedInUsers[i] = value; i++; value = br.readLine(); } Writer output = null; String eol = System.getProperty("line.separator"); output = new BufferedWriter(new FileWriter(file)); output.write(username); output.write(" Has logged in from "); output.write(returnIP.toString()); i = 0; while (loggedInUsers[i] != null) { output.write(eol + loggedInUsers[i]); i++; } output.close(); loopBreak = 1; } } } catch (IOException e){ } } }