Java sockets with thread execution -


I have coded a socket listener, which should listen on ports 80 and 81 and when the data reaches these ports, I advise this listener to concurrently codify these two ports and havas in the following manner.

  Import java.net. *; Import java.io * *; Import java.text.DateFormat; Import java.text.SimpleDateFormat; Public class Multiple Socket Surveyor executes Runnable {Private Int a; Private server connection; Private string timestamp; Private Ent ID; Public static zero main (string [] args) {// System.out.print ("ip"); // string gh = "12345"; //System.out.println(gh.substring (1,3)); Int port = 80; Int port 1 = 81; Int count = 0; Double A = 234.52121; //System.out.println (bf3.toString ()); {ServerSocket Socket 1 = Try New Server Socket (Port); Server Socket Socket 2 = New Serverset (Port 1); System.out.println ("Start multiple socket server"); Runnable runner = new multiple socket surfer (socket 1, ++ count); Runnable run = new multiple socket surfer (socket 2, ++ count); Thread thread = new thread (runner); Thread thread 1 = new thread (run); While (true) {// socket connection = socket1.accept (); Thread.start (); Thread1.start (); }} Hold (exception e) {}} multicask server (servercockets, int i) {this.connection = s; This.ID = i; } Public Zero Run () {while (true) {try {socket incoming = connection.accept (); BufferedInputStream = New BufferedInputStream (incoming.getInputStream ()); Character; While ((character = is.read ())! = - 1) {. . Here to deal with input data }} Hold (exception e) {}}}}  

But for some reason it does not seem to show threaded / concurrent behavior. I'm testing this code using Hyper-Terminal, and whenever I disconnect from Hyper-Terminal, the program execution stops and the "Socket is off" exception is raised.

Any sign will be very helpful

Cheers

You are starting thread in endless loop.

  while (true) {// socket connection = socket1.accept (); Thread.start (); Thread1.start (); }  

I think that though, it

 } catches (exception e) {}  

However, I suspect that the problem you describe is in the handling code that you did not include. A very clear idea: you do not call incoming.close () instead of connection.close () , do you


Comments

Popular posts from this blog

php - multilevel menu with multilevel array -

c# - TypeConverter in propertygrid only converts from string, not to -

jQuery UI: Datepicker month format -