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.

Einfaches Client-/ Serversystem

Empfohlene Antworten

Veröffentlicht

Hi!

Ich habe ein Problem... Ich versuche jetzt schon ewig ein genz einfaches

Client-/Serversystem aufzubauen. Der Client (ein Applet) soll eine

Verbindung zum Server (Konsolenanwendung) aufbauen und einen

Befehl rüberschicken. Den Befehl soll der Server auswerten und eine

ensprechende Antwort zurücksenden.

z.B. Befehl Datum -> Datum wird zurück gegeben

Befehl Zufall -> Zufallszahl wird zurück gegeben

etc.

Ich komme aber einfach nicht weiter.

Wer kann mir da helfen?

Hier ist mal der Code:

Client:

import java.awt.*;

import java.applet.*;

import java.io.*;

import java.util.*;

import java.net.*;



public class Client extends Applet {


	BorderLayout ly_Gesamt = new BorderLayout();

	BorderLayout ly_Oben = new BorderLayout();

	GridLayout ly_Unten = new GridLayout(1, 2);

	TextArea txta_Protokoll = new TextArea("", 10, 40, TextArea.SCROLLBARS_VERTICAL_ONLY);

	TextField txt_Befehl = new TextField(40);

	Panel pan_Oben = new Panel();

	Panel pan_Unten = new Panel();

	Button btn_Senden = new Button("senden");





	public void init() {

		pan_Oben.setLayout(ly_Oben);

		pan_Unten.setLayout(ly_Unten);

		pan_Oben.add("Center", txta_Protokoll);

		pan_Unten.add(txt_Befehl);

		pan_Unten.add(btn_Senden);

		setLayout(ly_Gesamt);

		add("Center", pan_Oben);

		add("South", pan_Unten);

		setBackground(Color.lightGray);

	}


	public void paint(Graphics g) {


	}


	public void senden() {

		try {

			txta_Protokoll.append("Open connection...\n");

			Socket Sock = new Socket("praktifix", 1234);

			InputStream in = Sock.getInputStream();

			OutputStream out = Sock.getOutputStream();


			txta_Protokoll.append("Sending command...\n");

			out.write(txt_Befehl.getText().getBytes());


			txta_Protokoll.append("Reciving: ");


			int len;

			byte[] b = new byte[100];

			txta_Protokoll.append("\n");

			while ((len = in.read() != -1) {

				txta_Protokoll.append(new String();

			}

			in.close();

			Sock.close();

			txta_Protokoll.append("\nConnection is closed!\n");

		}catch (IOException e) {

			System.err.println(e.toString());

			System.exit(1);

		}

	}


	public boolean action(Event evt, Object arg){


		if (evt.target instanceof Button) {

			String labl = (String)arg;

			if (labl.equals("senden")) {

				senden();

			}else{


			}

		}

		return true;	

	}

}[/code]






[b]Server:[/b]



[code] package myprojects.server; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import java.net.*; class Server extends Frame { public Server() { } public static void main(String args[]) throws IOException{ String strBefehl = new String(); System.out.println("Server is running..."); ServerSocket ServSock = new ServerSocket(1234); Socket Sock = ServSock.accept(); System.out.println("Connected to Client!"); OutputStream out = Sock.getOutputStream(); InputStream in = Sock.getInputStream(); int len; byte[] b = new byte[100]; while ((len = in.read(B)) != -1) { strBefehl = strBefehl + new String(B); } System.out.println("Command: " + strBefehl); System.out.println("Send Data..."); out.write(strBefehl.getBytes()); } }

Über jegliche Denkanstöße würde ich mich wirklich freuen! :D

MfG

backdraft

hehe, bei http://www.programmierer-board.de wollen dir welche helfen, mußt denen aber mal was genauer erklären...

Was funktioniert denn noch nicht? Ein paar Hinweise wären schon hilfreich...

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.