נשלח בתאריך: 28 May 2008 בשעה 22:35 | | IP רשוּם
|
|
|
|
בקוד הבא בשורה if (gettok(str,1,32) == "PING") למרות שgettok(str,1,32) כן מחזיר PING (בדקתי את זה על ידי הוספת System.out.println(gettok(str,1,32)) בשורה מעל) התוכנית אינה נכנסת לתוך הif מה לא עשיתי נכון?
קוד:
import java.io.*; import java.net.*; import java.util.*; public class EchoClient { static Scanner input = new Scanner(System.in); public static void main(String[] args) throws IOException { Socket echoSocket = null; PrintWriter out = null; BufferedReader in = null; try { echoSocket = new Socket("uk.quakenet.org",6667); out = new PrintWriter(echoSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host: taranis."); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for " + "the connection to: taranis."); System.exit(1); } out.println("NICK Zomeded"); out.println("USER Zomeded Zomeded2 Zomeded3 Zomeded4 Zomeded5 Zomeded6"); out.println("JOIN #dip"); BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); String str; str = in.readLine(); while (str != null) { System.out.println(str); if (gettok(str,1,32) == "PING") out.println("PONG " + gettok(str,2,32)); str = in.readLine(); } out.close(); in.close(); stdIn.close(); echoSocket.close(); } public static String gettok(String str,int p,int c) { int len = str.length(); int b,b1,b2; String str2; b = 0; b1 = -1; b2 = len; for (int i = 0; i < len; i++) { if (str.charAt(i) == c) { b=b+1; if (p-1 == b) b1 = i; if (p == b) b2 = i; } } str2=String.valueOf(str.charAt(b1+1)); for (int i = b1+2; i < b2; i++) { str2=str2+str.charAt(i); } return str2; } }
|
|
|
|