Portal > Foren > Java > Allgemeine Java-Programmierung > Probleme mit I/O-Stream-Auswertun
Antwort
 
Themen-Optionen
Alt 25.01.2006, 17:16 Nach oben    #1
Oliver O.
 
Benutzerbild von Xean
 
Registriert seit: 17.08.2005
Beiträge: 426
Standard Probleme mit I/O-Stream-Auswertun

hi, bin ein zimlicher "new-be" was ServerSocket und Socket programmierung an geht und hab ein problem was ich nicht verstehe:

der Client:
Code:
import java.net.*;
import java.io.*;

public class Client extends Thread{
    boolean running = true;
    long id;
    Socket s;
    String out = null;
    InputStream i;
    OutputStream o;
    /** Creates a new instance of Client */
    public Client() throws Exception{
       s = new Socket("localhost",7788);
       run();
    }
    
    public void run() {
        try{
            System.out.println("Start Client");
            i= s.getInputStream();
            o= s.getOutputStream();
            String out = "login;ClientName:password";
            o.write(out.getBytes());
            o.flush();
            while(running){
                String in = "";
                while(true){
                    char c = (char)i.read();
                    if(c != '#'){
                        in += c;
                    }else{
                        break;
                    }
                }
                parser(in.split(";"));
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    public void parser(String[] cmd) throws Exception {
        if(cmd[0].equals("login")){
            o.write("id;get#".getBytes());
            o.flush();
            System.out.print("Hallo");
        }if(cmd[0].equals("id")){
            id = Long.parseLong(cmd[1]);
            System.out.println(id);
        }
    }
    public static void main(String[] args) throws Exception{
        new Client();
    }
}
der Server:
Code:
import java.net.*;
import java.io.*;

public class Server extends Thread{
    ServerSocket s;
    InputStream i;
    OutputStream o;
    long id = 0;
    /** Creates a new instance of Server */
    public Server() throws Exception {
        s = new ServerSocket(7788);
        start();
    }
    public void run(){
        System.out.println("Start Server");
        try{
        while(true){
            Socket s = this.s.accept();
            i= s.getInputStream();
            o= s.getOutputStream();
            String in = "";
            while(true){
                char c = (char)i.read();
                if(c != '#'){
                    in += c;
                }else{
                    break;
                }
            }
            parser(in.split(";"));
        }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    
    public void parser(String[] cmd) throws Exception {
        if(cmd[0].equals("login")){
            o.write("login;true#".getBytes());
        }if(cmd[0].equals("id")){
            o.write(("id;" + (id++) + "#").getBytes());
        }
    }
    public static void main(String[] args) throws Exception{
        new Server();
    }
}
mein problem ist, dass wenn ich das prog starte, immer bis zur id abfrage beim client, also inder Zeile:
if(cmd[0].equals("id"))
weiter will er nicht. Warum??
Xean ist offline  
Add Post to del.icio.usBookmark Post in TechnoratiDiesen Beitrag zu Mister Wong hinzufügen!
Mit Zitat antworten
Alt 26.01.2006, 21:20 Nach oben    #2
Oliver O.
 
Benutzerbild von Xean
 
Registriert seit: 17.08.2005
Beiträge: 426
Standard

hi, hat sich erledigt...
hab String out = "login;ClientNameassword";
statt String out = "login;ClientNameassword#";
geschrieben...
Xean ist offline  
Add Post to del.icio.usBookmark Post in TechnoratiDiesen Beitrag zu Mister Wong hinzufügen!
Mit Zitat antworten
Antwort

Lesezeichen


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 
Themen-Optionen

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Probleme mit Strato / Arcor? MrNiceGuy Plauderecke 15 28.12.2006 23:35
Caching mittels dbm-Dateien, Probleme mit dba_popen() Ben PHP-Programmierung 4 27.07.2006 13:23
Probleme mit Anhängen Ben Archiv 0 16.06.2006 16:13
Layout Probleme VipViper2000 Desktop-Applikationen und Grafik 8 13.09.2005 22:35
Stream zeilenweiße auslesen mr.no Allgemeine Java-Programmierung 1 28.07.2005 13:21


Alle Zeitangaben in WEZ +2. Es ist jetzt 17:21 Uhr.


Powered by vBulletin® Version 3.7.3 (Deutsch)
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44