multithreading - Java network code not sending -
I write my first non-trivial Java application that uses:
- Networking
- A GUI
- Thread
This is an IM program when I send a message, the server does not output what it should do . I am sorry that this description is very bad, but I do not know how to narrow down the problem.
Public class metserve {// kikote public static records messages (int targ iad, int iid, string message) {connected client target client = iacquant (target id); // also runs System.out.println ("sending message:" + + "\ n \ n" + + "target ID" from +ID +); TargetClient.addOutCommand ("/ Message:" + IID + ":" + Message + "\ n");}} class connected client tool runnabel {public zero run () {string contact; contact = s.getInetAddress (); toString (); System.out.println (" Connect "+ contact;) Try out {Out.write (" / connect "+" \ n "); out.flush (); string command; while (true) {if (expired) {S.col ()) ; Break;} if (in.hasNextLine ()) {command = in.nextLine (); commandProcessor.addInCommand (command);} thread. Sleep (100 );}} Hold (exception e) {e.printStackTrace ();}} // snip public with add command (string command) {commandProcessor.addOutCommand (command); // // My guess is that the problem is this method As soon as the next line // does not print // // System.out.println ("+ + this ID +" has been received to send: "+ command");}} class command processor implementation Can be run {// Ecommerce Public Zero Run () {String current compound in; String current commandout; While (true) {try {currentCommandIn = inQueue.poll (); If (currentCommandIn! = Null) {System.out.println ("Processing:" + Current Commend In); String [] commandArr = command parser Pars Residential Commands (Current Commend In); If (commandArr [0] .equalsIgnoreCase ("message")) {int target = Integer.parseInt (commandArr [1]); String message = command ARR [2]; // It definitely runs System.out.println ("send message:" + target); MachatServer.SendMessage (Target, this.conId, Message); } Else if (commandArr [0] .equalsIgnoreCase ("quit")) {// Tell us to disconnect the server. MachatServer.disconnect (conId); break; } CurrentCommandOut = outQueue.poll (); If (currentCommandOut! = Null) {try {out.write (currentCommandOut + "\ n"); System.out.println (Current Commandout + "Sent"); Out.flush (); } Hold (IOException e) {e.printStackTrace (); }}} Hold (exception e) {e.printStackTrace (); } Public synchronized zero addOutCommand (string command) {if (command! = Null) {try {outQueue.push (command); } Hold (exception e) {System.out.println (command); E.printStackTrace (); } // does not print system.out.println ("ready to send:" + command); } Else {System.out.println ("empty command received"); } // snip}
The full source code has expired, if I have compromised the problem incorrectly.
The expected output should be when I send Telnet "0: test", send it to "/ message: myid : the test" ID with the customer. The actual output is nothing.
area outQueue
is not started in the command processor, and You have to find out this by printStackTrace ()
.
Comments
Post a Comment