import java.io.IOException; import java.io.*; import java.net.InetAddress; //clase de manejo capa ip import java.net.InetSocketAddress; //implementacion de socket de la clase abstracta socketaddress import java.net.SocketAddress; //clase abstracta para implenentar socket import java.nio.ByteBuffer; //clase abstracta para la implementaciond e buffer import java.nio.charset.Charset; import java.nio.CharBuffer; import java.nio.charset.CharsetEncoder; import java.lang.String; import java.io.PrintStream; import com.sun.nio.sctp.MessageInfo; import com.sun.nio.sctp.SctpChannel; /** * @author sandarenu * $LastChangedDate$ * $LastChangedBy$ * $LastChangedRevision$ * Sintaxis es java Cliente */ public class Cliente { static int SERVER_PORT = 3456; static int BUFFER_SIZE = 80; public static void main(String[] args) throws IOException { try { InetSocketAddress socketAddress = new InetSocketAddress(args[0], SERVER_PORT); ByteBuffer byteBuffer = ByteBuffer.allocate(BUFFER_SIZE); CharBuffer cbuf = CharBuffer.allocate(BUFFER_SIZE); Charset charset = Charset.forName("utf-8"); CharsetEncoder encoder = charset.newEncoder(); BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); SctpChannel sctpChannel = SctpChannel.open(socketAddress, 1 ,1);//socketAddress, 1 ,1 //sctpSChannel.bind(socketAddress); /* handler to keep track of association setup and termination */ //AssociationHandler assocHandler = new AssociationHandler(); MessageInfo messageInfo = MessageInfo.createOutgoing(null, 0); System.out.println("messageInfo = " + messageInfo); String in; SctpChannel sc; do { in= stdIn.readLine(); cbuf.put(in.toCharArray()).flip(); encoder.encode(cbuf, byteBuffer, true); byteBuffer.flip(); //System.out.println(buf.toString()); sctpChannel.send(byteBuffer, messageInfo); cbuf.clear(); byteBuffer.clear(); }while(!in.equals("exit")); System.out.println("close connection"); sctpChannel.close(); } catch (Exception e) { e.printStackTrace(); } } public static void printInfo(SctpChannel sctpChannel) { try { System.out.println("sctpChannel.getRemoteAddresses() = " + sctpChannel.getRemoteAddresses()); System.out.println("sctpChannel.getAllLocalAddresses() = " + sctpChannel.getAllLocalAddresses()); System.out.println("sctpChannel.isConnectionPending() = " + sctpChannel.isConnectionPending()); System.out.println("sctpChannel.isOpen() = " + sctpChannel.isOpen()); System.out.println("sctpChannel.isRegistered() = " + sctpChannel.isRegistered()); System.out.println("sctpChannel.provider() = " + sctpChannel.provider()); System.out.println("sctpChannel.association() = " + sctpChannel.association()); } catch(IOException e) { e.printStackTrace(); } } }