Socket xSocket client (nonblocking)

Mericon

Mitglied
Guten abend,

ich habe ein problem und zwar will ich einen nonblocking client mit xsocket realisieren aber die ide schmeißt mir immer einen fehler an den kopf bevor ich den code testen kann...

und zwar folgende im try catch bereich:

Code:
illegal start of type

';' expected

ich kann keinen fehler finden bitte gebt mir eine starthilfe oder nen ganz großen zaunpfahl 🙂

hier ist noch der code (IDE netbeans):

Java:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Client;

import java.io.IOException;
import java.nio.BufferUnderflowException;
import org.xsocket.MaxReadSizeExceededException;
import org.xsocket.connection.IDataHandler;
import org.xsocket.connection.INonBlockingConnection;
import org.xsocket.connection.NonBlockingConnection;

/**
 *
 * @author Mericon
 */
public class client{
    String host ="127.0.0.1";
    Integer port = 2222;
// defining the client handler (here as a anonymous inner class)
    IDataHandler clientHandler = new IDataHandler() {
 
    public boolean onData(INonBlockingConnection nbc) 
             throws IOException, 
             BufferUnderflowException, 
             MaxReadSizeExceededException {
 
      // read the whole logical part or throwing a BufferUnderflowException
      String res = nbc.readStringByDelimiter("\r\n");
      //...

      return true;
   }
};
    try{
// opening the connection
INonBlockingConnection nbc = new NonBlockingConnection(host, port, clientHandler);
nbc.write("Hello");
}catch(IOException e)
{
    System.out.println("Error: "+e);
}
// do something else. Receiving data causes that the client 
// handler's onData method will be called (within a dedicated thread)
//...  
}

danke euch
 
try muss innerhalb einer Methode, eines Konstruktors oder meinetwegen eines Initialisier-Blocks stehen,
bei dir direkt in der Klasse oder sogar erst hinter der Klasse, das Semikolon vor dem try auch fraglich,

sieht man hier doch schon recht gut an der Einrückung,
Klassen übrigens besser groß schreiben, dafür packages klein..
 

Neue Themen


Zurück
Oben