java - Client-server, can't figure it out how to make multiclients sending string to one server -


need bit of help.. creating project client-server make working on watching files. working,exept part should messages client. don't know why not it.

package server;  import java.io.filenotfoundexception;  import java.io.ioexception;  import org.json.simple.parser.parseexception;  public class server {  public static void main(string[] args) throws filenotfoundexception, ioexception, parseexception, classnotfoundexception {     new config();     new clientcomm();     while(true){          clientcomm.getlineandtypefromclient();      }     system.out.println(clientcomm.ois.available()); } } 

client.java:

package client;  public class client {       public static void main(string arg[]) throws exception{          new config();         new servercomm();         if(servercomm.sendauth() == true) {             system.out.println("client connected server : " + servercomm.getsocket().isconnected());             new fileprocessing();         }      } } 

servercomm.java : sending info server client.

package client; import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.io.objectoutputstream; import java.net.socket; import java.net.unknownhostexception;  public class servercomm{      private static socket socket;     private static objectoutputstream oos;       public servercomm() throws unknownhostexception, ioexception {          socket = new socket(config.gethost(), config.getport());         oos = new objectoutputstream(socket.getoutputstream());      }      protected static void sendline(string line, string type) throws ioexception{          string[] = {line,type};         oos.writeunshared(a);         oos.flush();         system.out.println(oos);         oos.reset();     }      protected static socket getsocket() {         return socket;     }      @suppresswarnings("resource")     protected static boolean sendauth() throws ioexception {          string project_id = config.getproject_id();         string user_id = config.getuser_id();          string[] auths = {project_id, user_id};         oos.writeunshared(auths);         oos.flush();         oos.reset();         system.out.println(oos);         return true;      }     } 

clientcomm.java : receiving info client.

package server;  import java.io.bufferedreader; import java.io.bufferedwriter; import java.io.ioexception; import java.io.inputstreamreader; import java.io.objectinputstream; import java.io.objectoutputstream; import java.io.outputstream; import java.io.outputstreamwriter; import java.io.printwriter; import java.net.serversocket; import java.net.socket; import java.net.unknownhostexception; import java.util.arraylist;   public class clientcomm{      private static socket client;     private static serversocket server;     public static objectinputstream ois;      public clientcomm() throws classnotfoundexception {         try {             server = new serversocket(config.getport());             system.out.println("server started");              while (true)             {                 client = server.accept();                 checkauth();                 system.out.println("new connection");              }          } catch (ioexception e) {             e.printstacktrace();         }       }      protected static void getlineandtypefromclient() throws ioexception, classnotfoundexception {          string[] variables = (string[]) ois.readobject();         for(string variable : variables) {             system.out.println(variable);         }         ois.reset();     }      private void checkauth() throws ioexception, classnotfoundexception {         arraylist<string> auths = new arraylist<string>();         ois = new objectinputstream(client.getinputstream());         string[] autharray = (string[]) ois.readobject();         for(string auth : autharray) {             auths.add(auth);         }         int temp = 0;         for(int = 0 ; < auths.size() ; i++) {              if(config.getprojectid().equals(auths.get(i)) || config.getuserid().equals(auths.get(i)) ){                 temp += 1;             }             else {                 temp -= 1;             }          }         if(temp == auths.size()) {             temp = 0;         }         else {             system.out.println("auth failed");             temp = 0;             client.close();         }         }  } 

tell me im doing wrong! :)


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -