Handle Connection Problem

Crue

Mitglied
Hi

Ich habe da ein Problem.

Meine empfangsMethode:

Java:
public class Server
{

	
  private static void handleConnection( Socket client ) throws IOException
  {
	
	String command="";
    Scanner     in  = new Scanner( client.getInputStream() );
    PrintWriter out = new PrintWriter( client.getOutputStream(), true );

    String commandIn = in.nextLine();
    if(commandIn!=""){
    	Verarbeitung.verarbeiten(commandIn);
    }
  }

  public static void empfangen(ServerSocket server)throws IOException
  {
   

    while ( true )
    {
      Socket client = null;

      try
      {
        client = server.accept();
        handleConnection ( client );
      }
      catch ( IOException e ) {
        e.printStackTrace();
      }
      finally {
        if ( client != null )
          try { 
        	  client.close(); 
        	  }
        catch ( IOException e )
        {
        	
        }
      }
    }
  }
}

Ich sende mit der unteren Methode einen String, zwar wird dieser übertragen, aber irgendwie fehlerhaft.
Wenn ich zum Beispiel den String "Auto" übertrage, dann sollte commandIn = "Auto" sein, aber das ist es irgendwie nicht, den wenn ich mit if soetwas abfrage: if(commandIn=="Auto") dann funktioniert das nicht...aber wenn ich nur abfrage: if(commandIn!="") dann wird die schleife ausgeführt...

Fals es schlecht vormuliert ist, tut dies mir Leid, weisst nicht genau wie ich das sonst beschrieben soll....

Hier meine Sende Methode:

Java:
import java.net.*;
import java.util.Scanner;
import java.io.*;

public class Sender
{
  public static void senden(String text)
  {
    Socket server = null;

    try
    {
      server = new Socket( "localhost", 1000 );
      //Scanner     in  = new Scanner( server.getInputStream() );
      PrintWriter out = new PrintWriter( server.getOutputStream(), true );

      out.println( text );
    }
    catch ( UnknownHostException e ) {
      e.printStackTrace();
    }
    catch ( IOException e ) {
      e.printStackTrace();
    }
    finally {
      if ( server != null )
        try 
        { 
        	server.close(); 
        }
        catch ( IOException e ) 
        {
        	
        }
    }
  }
}
 
Zuletzt bearbeitet:
Ähnliche Java Themen
  Titel Forum Antworten Datum
x46 Connection reset by peer: socket write error Netzwerkprogrammierung 6
F Probleme mit Connection Reset bei Telnet Verbindung Netzwerkprogrammierung 1
Thalion TCP Connection zu langsam Netzwerkprogrammierung 2
S Client Server Connection Netzwerkprogrammierung 4
R Socket InputStream readObject > Connection Reset Netzwerkprogrammierung 3
L ssh connection; Zugriff auf 'screen' Prozess Netzwerkprogrammierung 5
C Client connection per Portforwarding auf einen lokalen Serverport Netzwerkprogrammierung 3
M Connection refused? Netzwerkprogrammierung 2
D Connection refused Netzwerkprogrammierung 3
B Client/Server Connection Problem Netzwerkprogrammierung 2
D Socket Socket absichtlich so schließen, dass Gegenseite java.net.SocketException: Connection reset wirft Netzwerkprogrammierung 4
C Socket Connection refused bei Internetverbindung - Welcher Port? Netzwerkprogrammierung 5
K Socket Exception Connection reset Netzwerkprogrammierung 9
VfL_Freak Socket SocketException: Connection reset Netzwerkprogrammierung 11
C Socket Socket: Connection timed out Netzwerkprogrammierung 3
T Empfangen klappt Senden nicht - Connection timed out Netzwerkprogrammierung 12
H java.net.ConnectException: Connection refused Netzwerkprogrammierung 3
Z Socket Connection reset by peer nur per IP nicht über localhost Netzwerkprogrammierung 13
RELAXccc HTTP Connection timed out: connect ?an was kann es liegen? Netzwerkprogrammierung 4
G Exception: Connection reset by peer: socket write error Netzwerkprogrammierung 2
N Socket verliert die Connection. Netzwerkprogrammierung 4
A UCP Connection über Proxy möglich? Netzwerkprogrammierung 7
M RMI - Connection Problem Netzwerkprogrammierung 7
trash HTTP Internet Connection bei Proxy ?! Netzwerkprogrammierung 3
D Client Server Problem, Methode readline() löst SocketException "Connection reset" aus Netzwerkprogrammierung 8
H RMI Connection refused bei RMI-Registry Netzwerkprogrammierung 10
S SSH-Connection - Auto-Vervollständigung mittels TAB Netzwerkprogrammierung 4
A Chatprogramm: Connection refused Netzwerkprogrammierung 4
T RMI RMI und VPN - callbackObject Connection refused Netzwerkprogrammierung 13
A Socket Client Server Connection wird aufgebaut aber keine daten geschickt. Netzwerkprogrammierung 5
J Connection Speed Test ohne Applet Netzwerkprogrammierung 5
0din Connection refused bei localhost?! Netzwerkprogrammierung 7
M FTP-Connection über FTP-Proxy Netzwerkprogrammierung 20
T Wie connection Reset abfragen/abfangen? Netzwerkprogrammierung 10
A RMI java.rmi.ConnectException: Connection refused to host: 1 Netzwerkprogrammierung 4
M chat funktioniert nicht (Connection refused: connect) Netzwerkprogrammierung 3
G InputStreamReader lässt TCP-Connection offen Netzwerkprogrammierung 9
X URL connection Problem Netzwerkprogrammierung 3
R ConnectException: Connection refused to host: 192.168.1.4 ? Netzwerkprogrammierung 8
sparrow Connection Reset bei Webserver, Java WebStart als Client Netzwerkprogrammierung 9
tfa RMI-Problem: Connection refused to host: 127.0.0.2 Netzwerkprogrammierung 4
G Connection zu MySQL ohne ODBC Netzwerkprogrammierung 8
IT-MaD Connection reset by peer: socket write error Netzwerkprogrammierung 2
B RMI & Connection refused to host Netzwerkprogrammierung 12
G httpUnit: Connection timed out Netzwerkprogrammierung 3
lhein java.io.IOException: Unable to establish loopback connection Netzwerkprogrammierung 4
Paule Connection Applet Servlet ohne Socket bzw RMI Netzwerkprogrammierung 2
B Multithreaded Server: Connection reset Netzwerkprogrammierung 4
T JDBC Verbindungsabbruch (Connection reset) Netzwerkprogrammierung 2
M SocketException: Connection reset Netzwerkprogrammierung 10
G MAC / IP Connection Netzwerkprogrammierung 10
M Problem: connection abbrechen und login erkennen Netzwerkprogrammierung 2
M Umlaute gehen bei URL Connection verloren Netzwerkprogrammierung 6
M seltsam: java.net.SocketException: Connection reset Netzwerkprogrammierung 1
B RMI Connection Problem Netzwerkprogrammierung 13
T Dateien wia P2P Connection versenden Netzwerkprogrammierung 2
D Socketverbindung schlägt fehl - Connection refused: connect Netzwerkprogrammierung 4
H java.net.SocketException: Software caused connection abort Netzwerkprogrammierung 4
R FTP Connection zu Server Netzwerkprogrammierung 4
M Ausgangsport für FTp-Connection festlegen??? Netzwerkprogrammierung 3
I Socket Problem mit den WebSocket Antworten der Discord API Netzwerkprogrammierung 0
K Java Websocketserver Problem | Android to Pi Netzwerkprogrammierung 1
C RMI Produzent-Verbraucher-Problem - Code review Netzwerkprogrammierung 12
B Socket Bilder verschicken via Sockets. Heap-Problem. Netzwerkprogrammierung 2
S Problem bei dem Bluetoothverbindungsaufbau Netzwerkprogrammierung 2
G Server-Client IO Problem Netzwerkprogrammierung 6
M Netty - TCP Problem Netzwerkprogrammierung 4
L Socket Problem mit Server Netzwerkprogrammierung 1
J Chat Server starten über GUI problem Netzwerkprogrammierung 4
M Problem bei Socket (MultiplayerSpiel) Netzwerkprogrammierung 4
M Socket CDI, Websocket reference Problem ! Netzwerkprogrammierung 2
Shams Problem mit Eventbus in Verbindung mit Server Netzwerkprogrammierung 0
G apache httpClient Problem. Netzwerkprogrammierung 5
H Problem mit ObjectStreams Netzwerkprogrammierung 3
A Problem beim Senden von Client zu Server Netzwerkprogrammierung 10
D Socket BufferedWriter/Reader Problem Netzwerkprogrammierung 1
Maxim6394 Problem mit Socks5 Implementierung Netzwerkprogrammierung 0
E HttpUrlConnection Cookie Problem Netzwerkprogrammierung 0
X Problem mit vielen Bytes über Socket Netzwerkprogrammierung 23
O 4Gewinnt Multiplayer - Netzwerk Problem (TCP) Netzwerkprogrammierung 1
A Socket Socket-Problem - Object wird nicht übertragen Netzwerkprogrammierung 3
R Problem beim Programmieren eines Chatprogramms Netzwerkprogrammierung 5
E einfaches Problem: Session-Handling bei Servlets Netzwerkprogrammierung 5
G Problem mit einem FileWatcher Netzwerkprogrammierung 7
T Socket Server starten Thread Problem Netzwerkprogrammierung 12
G Problem mit STATIC-Verständnis Netzwerkprogrammierung 8
S Umstellung AS400 auf Postgre - Problem beim Arbeiten mit Metadaten Netzwerkprogrammierung 2
J Facelets Include Rendered Problem Netzwerkprogrammierung 2
J Socket Problem mit C++/Java Netzwerkprogrammierung 20
P Problem mit Datagram-Sockets Netzwerkprogrammierung 2
G Socket NIO2 Problem mit AsynchronousSocketChannel beim Schließen Netzwerkprogrammierung 3
G Cookie Verwaltungs Problem nach Login auf InetSeite (Wo utma-Cookie?) Netzwerkprogrammierung 18
C Socket Problem mit ObjectInput/OutputSream Netzwerkprogrammierung 7
B Socket Problem mit Netzwerkchat Netzwerkprogrammierung 21
D RMI Problem beim shutdown von verteilter CORBA-Anwendung Netzwerkprogrammierung 6
Maxim6394 ipv6 Problem Netzwerkprogrammierung 2
Maxim6394 Proxyserver Performance Problem Netzwerkprogrammierung 11
M Problem Client - Server Sockets: .ready() wird nie true! Netzwerkprogrammierung 6
C Socket Problem mit ObjectInput/OutputSream Netzwerkprogrammierung 5
B RMI und Problem mit rmic-Tool Netzwerkprogrammierung 3

Ähnliche Java Themen

Neue Themen


Oben