Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Netzwerkprogrammierung problem

Empfohlene Antworten

Veröffentlicht

Hi,

Heute wende ich mich mal mit einem Java problem an euch!

Mein Referats Thema ist, wie der Titel sagt, Netzwerkprogrammierung.

Ich habe bereits einen Chat in Grafischer Oberfläche erstellt mit Thread's.

Nun ist mein Problem:

Diese GUI soll nun durch Consolen eingabe ersetzt werden.

(Eclipse 3.1.1, JRE 1.6)

In der GUI sah der Code für das schreiben in den PrintStream wie folgt aus:

(ich implementiere das Interface Runnable)


	public boolean action(Event e, Object what)

	{

		if (e.target == inputfield)

		{

			String inp = (String) e.arg;

                        // out => PrintStream

			out.println(inp);

			inputfield.setText("");

			return true;

		}


		return false;

	}
Wie schaffe ich es eine so ähnliche Methode zu schreiben?! Ich wollte den BufferedReader bzw. InputStreamReader doch das funzt bei mir irgendwie nicht richtig...
		String line;

		String s;

		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));

		try

		{

			while(true)

			{


				s = buf.readLine();

				if(s.length() != 0)

				{	

					out.println(cln + ": " +s);

				}


				// in => DataInputStream

				line = in.readLine();

				System.out.println("Debug");

				if(line!=null)

					System.out.println(line+'\n' );

			}

		} catch (IOException e) { }

das funzt bei mir irgendwie nicht richtig...
Wie äußert sich dieses "nicht richtig"?

Wird eine Fehlermeldung angezeigt, erfolgt keine Ausgabe, explodiert dein PC während des Kompiliervorgangs? Die Glaskugel ist in Reparatur, also ein wenig ausführlicher bitte!

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.