i trying search server , once client finds it, stops searching new servers. client finds server, can messages server trys connecting other once cant write server.
can u guys tell me need code?
ty bono
for (pcip = 0; pcip <= 253; pcip++) { clientverbindung = new chatsocket(client.getusername(), /* * die ip * welche * der * client * verbindet */ "10.4.0." + pcip, /* der port welcher verwendet wird */3005, client); clientverbindung.start(); }
chatsocket:
public class chatsocket extends thread { private string namedesusers; private string ip; private int port; private p2p client; private string user; private string path; private datainputstream instream; private dataoutputstream outstream; public chatsocket(string namedesusers, string ip, int port, p2p client) { this.namedesusers = namedesusers; this.port = port; this.ip = ip; this.client = client; } public void run() { try { socket clientsocket = new socket(ip, port); inputstream in = clientsocket.getinputstream(); outputstream out = clientsocket.getoutputstream(); instream = new datainputstream(in); outstream = new dataoutputstream(out); // intepretiert den erhaltenen text. passiert nur bei diesem socket // und nicht umbedingt auch beim sender outstream.writeutf(namedesusers); while (true) { string utf = instream.readutf(); client.setmessage("server", utf); } // mögliche fehlermeldungen } catch (unknownhostexception uhe) { system.out.println("client fehler: " + uhe.tostring()); } catch (ioexception ioe) { system.out.println("client fehler: " + ioe.tostring()); } system.out.println("die verbindung wurde geschlossen."); } public void sendtext(string message) { try { if (message != null) { // nimmt den aktuellen text aus dem clienttext und schickt ihn // den server outstream.writeutf(message); } // mögliche fehlermeldungen } catch (ioexception ioe) { system.out.println("fehler beim senden im client: " + ioe.tostring()); } catch (nullpointerexception npe) { system.out.println("fehler beim senden im client: " + npe.tostring()); } } }
if there isn't valid connection connectexception.
ergo, if don't exception, have valid connection.
hard see mystery is.
Comments
Post a Comment