ERLEDIGT
JA
JA
ANTWORTEN
5
5
ZUGRIFFE
716
716
EMPFEHLEN
-
Hallo bin leider noch ein Anfäger in Java ich sitze hier jetzt schon seit Tagen daran und bekomme es einfach nicht hin...
ich möchte von einer UNIX Anlage über IP und Port eine Verbindung aufbauen
und Daten lesen und schreiben können
Ich kann die Anlage pingen und bekomme auch Antwort
Prot. soll Telnet auf Port 23 sein
die Codierung soll mit ISO 8859-1 erfolgen doch leider
happert es bei mir schon an dem Auslesen der Daten
import java.awt.*;Code :1
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.nio.*;
import java.rmi.*;
import java.math.*;
public class fenster
extends JFrame
{
public static void main(String[] args)
{
JFrame fn = new Hauptfenster();
fn.setVisible(true);
fn.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
} );
}
}
class Hauptfenster
extends JFrame
{
public Hauptfenster()
{
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
Menuleiste menu = new Menuleiste();
contentPane.add(menu, "North");
Mittelpanel mitte = new Mittelpanel();
contentPane.add(mitte, "Center");
setSize(1000,768);
setTitle("Juergen`s Orga-Soft");
}
}
class Menuleiste
extends JMenuBar
{
public Menuleiste()
{
JMenu datei = new JMenu("Datei");
JMenuItem neu = new JMenuItem("Neu");
datei.add(neu);
add(datei);
}
}
class Mittelpanel
extends JPanel
{
JTextArea area = new JTextArea(40, 80);
public Mittelpanel()
{
String host = "192.200.100.254";
int port = 23;
try
{
Socket soc = new Socket("192.99.100.254", 23);
soc = new Socket(InetAddress.getByName(host), port);
BufferedReader in = new BufferedReader(
new InputStreamReader(soc.getInputStream()));
PrintWriter out = new PrintWriter(soc.getOutputStream());
String str;
while((str = in.readLine()) != null)
{
StringBuffer buf = new StringBuffer();
buf.append(in);
buf.append(area);
}
} catch (Exception e)
{ area.append("Fehler " + e); }
add(area);
}
}
[Code :1
Geändert von Juergen78 (28.06.06 um 22:12 Uhr)
-
Alles schön und gut, aber der Netzwerkteil wird so sicher nicht funktionieren. Da er immer eine ganze Zeile einlesen will, was aber vorraussetzt das er das Returnzeichen als Endzeichen hat, was hier aber leider nicht zutrifft.
Du solltest dich mal in die Telnetspezifikation einlesen bzgl. was er sendet bzw. was er als Antwort erwartet, darauf musst du dann die Netzwerkschnittstelle aufbauen. Eventuell wäre es sogar einfacher das du dir selber einen eigenes Serverinterface baust.
mfg 4menworld:~ # cd /
world:/ # rm -rf *
-
12.02.05 19:04 #3
- Registriert seit
- Jun 2002
- Ort
- Saarbrücken (Saarland)
- Beiträge
- 9.886
- Blog-Einträge
- 29
Hallo!
Weshalb immerwieder das Rad neu erfinden?
http://jakarta.apache.org/commons/net/
Gruß TomJava rocks!
How to become a good Java Programmer?
Does IT in Java and .Net
The only valid measurement of code quality: WTFs / minute
Blog
Xing
Twitter
-
Nun ja er sagte ja er sei noch Anfänger deshalb dachte ich auch eher an lerning by doing. Oder anders gesagt daran hab ich mal wieder nicht gedacht
.
mfg 4menworld:~ # cd /
world:/ # rm -rf *
-
---------------------
Geändert von Juergen78 (21.03.06 um 22:22 Uhr)
-
Bin leider immer noch nicht weiter,
benötige eine Emulation welche Daten im Mode VT100 überträgt.
Habe von der Firma AppGate ein TelnetClient gefunden
weiss aber nicht wie ich den Terminal auf VT100 setzen kann.
Die Datei habe ich unter http://www.appgate.com/products/80_M...Term_Download/
heruntergeladen.
/******************************************************************************
*
* Copyright (c) 1999-2005 AppGate Network Security AB. All Rights Reserved.
*
* This file contains Original Code and/or Modifications of Original Code as
* defined in and that are subject to the MindTerm Public Source License,
* Version 2.0, (the 'License'). You may not use this file except in compliance
* with the License.
*
* You should have received a copy of the MindTerm Public Source License
* along with this software; see the file LICENSE. If not, write to
* AppGate Network Security AB, Otterhallegatan 2, SE-41118 Goteborg, SWEDEN
*
*****************************************************************************/
package examples;
import java.net.Socket;
import java.io.IOException;
import java.awt.Frame;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.mindbright.terminal.TerminalWin;
import com.mindbright.terminal.LineReaderTerminal;
import com.mindbright.terminal.GlobalClipboard;
import com.mindbright.terminal.TerminalFrameTitle;
import com.mindbright.net.telnet.TelnetTerminalAdapter;
/**
* Open a telnet window and connect with the telnet protocol. SSH is
* not involved att all.
* <p>
* Usage:
* <code> java -cp examples.jar examples.Telnet
* [<em>server</em>[:<em>port</em>]]
*/
public class Telnet extends WindowAdapter {
private Socket socket;
private String remoteHost;
private int remotePort;
private LineReaderTerminal lineReader;
private TelnetTerminalAdapter telnetAdapter;
/**
* Constructor which will cause the window to prompt the user for
* the server to connect to.
*/
public Telnet() {
this(null, -1);
}
/**
* Constructor which will cause a connection to the default port (23)
* on the given host.
*/
public Telnet(String remoteHost) {
setFromHostString(remoteHost);
}
/**
* Constructor which will cause a connection to a specified port
* on the given host.
*/
public Telnet(String remoteHost, int remotePort) {
this.remoteHost = remoteHost;
this.remotePort = remotePort;
}
/**
* Create the terminal window and connect to the remote host.
*/
public void startMeUp() {
Frame frame = new Frame();
TerminalWin terminal = new TerminalWin(frame);
/*
* Create terminal window
*/
terminal.setClipboard(GlobalClipboard.getClipboardHandler());
frame.setLayout(new BorderLayout());
frame.add(terminal.getPanelWithScrollbar(), BorderLayout.CENTER);
TerminalFrameTitle frameTitle =
new TerminalFrameTitle(frame, "Telnet (not connected)");
frameTitle.attach(terminal);
frame.addWindowListener(this);
frame.pack();
frame.show();
try {
/*
* Prompt for remote host if not specified
*/
if(remoteHost == null) {
lineReader = new LineReaderTerminal(terminal);
String host = null;
do {
host = lineReader.promptLine("\r\nremote host[
ort] : ",
null, false);
} while(host == null || host.trim().length() == 0);
setFromHostString(host);
lineReader.detach();
}
// Connect to remote host
socket = new Socket(remoteHost, remotePort);
// Attach the terminal emulator to the socket
telnetAdapter = new TelnetTerminalAdapter(socket.getInputStream(),
socket.getOutputStream(),
terminal);
// Update window title to reflect where we are connected
frameTitle.setTitleName(
"telnet@" + remoteHost
+ (remotePort != 23 ? (":" + remotePort) : ""));
// Wait for connection to close
telnetAdapter.getTelnetNVT().getThread().join();
/*
* Check that the terminal is still in local echo mode
* If so, print a message that we have disconnected
*/
if(telnetAdapter.isBuffered()) {
lineReader = new LineReaderTerminal(terminal);
lineReader.promptLine("\n\rTelnet session was closed, press <return> to close window", null,
false);
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
} finally {
// Close the window
frame.dispose();
}
}
/**
* Parse remote host name. This sets the remote host to connect
* to. It also looks if a port-number has been specified via the
* :<em>portnr</em> mechanism.
*/
private void setFromHostString(String remoteHost) {
if(remoteHost == null) {
return;
}
int i = remoteHost.indexOf(':');
if(i != -1) {
try {
this.remotePort =
Integer.parseInt(remoteHost.substring(i + 1));
} catch (Exception e) {
this.remotePort = 23;
}
remoteHost = remoteHost.substring(0, i);
} else {
this.remotePort = 23;
}
this.remoteHost = remoteHost;
}
/**
* Run the application
*/
public static void main(String[] argv) {
if(argv.length > 1) {
System.out.println("usage: Telnet <server[
ort]>");
System.exit(1);
}
Telnet telnet = new Telnet(argv.length > 0 ? argv[0] : null);
telnet.startMeUp();
System.exit(0);
}
/**
* Handles window close events by closing the socket to the server
* (if any).
*/
public void windowClosing(WindowEvent e) {
if(socket != null) {
try {
socket.close();
} catch (IOException ee) { /* don't care */
}
}
if(lineReader != null) {
lineReader.breakPromptLine("");
}
}
}Geändert von Juergen78 (16.07.06 um 02:02 Uhr)
Ähnliche Themen
-
unix erlaubt mysql nicht zu schreiben
Von airtime im Forum Linux & UnixAntworten: 13Letzter Beitrag: 23.09.10, 13:44 -
J2ME (Java Mobile) Daten lesen, schreiben und speichern
Von MC_Basstard im Forum JavaAntworten: 0Letzter Beitrag: 14.01.10, 14:30 -
RandomAccessFile schreiben-lesen-schreiben-lesen
Von SMoeller im Forum JavaAntworten: 1Letzter Beitrag: 03.12.06, 15:39 -
Binäre Daten lesen/schreiben
Von grashupfa im Forum PHPAntworten: 4Letzter Beitrag: 23.02.04, 21:46 -
Daten aus Access DB lesen und schreiben
Von aspnewbie im Forum Relationale DatenbanksystemeAntworten: 0Letzter Beitrag: 04.08.03, 12:11





Zitieren

Login





