I have following code. One reads a File called "denglish.txt" splits it into words and sends every 2nd word over Tcp socket connection to a server. The Server is now supposed to read this word and compare a to a word from a dictionary. Weird thing is the comparison always fails if i send it that way. But if the clients sends something like out.Print("make") it works . I really dont understand why its like this. I can send and print out the word from the client on the Server and he prints out the correct words but the stringcompare fails. MAybe someone can help me. THank you guys
Socket socket = new Socket ("localhost" , 47777);
PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
//Socket socket1 = new Socket ("localhost" , 47778);
//PrintWriter out1 = new PrintWriter(socket1.getOutputStream(),true);
String line;
BufferedReader text = new BufferedReader(new InputStreamReader(new FileInputStream("denglisch.txt")));
String text1 = "";
while((line = text.readLine()) != null) { // handle lines
text1 = text1 + line;
}
int i = 0;
//out.println("make");
StringTokenizer tokenizer = new StringTokenizer( text1,",.\" : !" );
while ( tokenizer.hasMoreTokens() )
{
if (i % 2 == 0)
{
out.println(tokenizer.nextToken().toLowerCase().toString());
out.flush();
}
if (i % 2 ==1 )
{
//out1.println(tokenizer.nextToken());
}
i = i+1;
Server CODE
//Server Codepublic
<pre> filteritserver(BufferedReader dict, String plusminus){
this.dict = dict;
this.port = 47777;
this.plusminus = plusminus;
}
public void run() {
ServerSocket server;
boolean isopen = false;
while (isopen == false){
try {
System.out.println(port);
server = new ServerSocket(port);
Socket cSocket = server.accept();
msg = new BufferedReader(new InputStreamReader(cSocket.getInputStream()));
isopen = true;
} catch (IOException e1) {
// TODO Auto-generated catch block
System.out.println("Port is already in used trying next one");
port = port +1;
}
}
System.err.println(port);
int i = 0;
String s = "word";
try {
while ((word = msg.readLine())!= null)
// while ( i < 3)
{
//System.out.println("prozess started und das Vorzeichen ist "+plusminus);
// System.out.println("das Wort "+ word +" ist hier angekommen");
try {
while(true) { // blunt sequential dictionary search
String line = dict.readLine();
//System.out.println(line);
if(line == null){
break;
}
else if(word.compareTo(line) < 0)
{
if (plusminus.equals("-"))
{
System.out.println("Dieses Wort kommt im Dictionary nicht vor " + word);
}
}
else if(word.compareTo(line)== 0 ){
if (plusminus.equals("+")){
System.out.println("Dieses Wort kommt im Dictionary 1234 vor " + word);
}
break;
}
else /* word.compareTo(line) > 0 */ continue; }
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}