Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Tags: CSharp,SimplestChat,JChannel,ReceiverAdapter,BufferedReader,InputStreamReader,Message, Created At: 10/24/2016 8:15:45 PMViews:

HTML view:
Copy Source | Copy HTML
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3.  
  4. import org.jgroups.JChannel;
  5. import org.jgroups.Message;
  6. import org.jgroups.ReceiverAdapter;
  7.  
  8. public class SimplestChat {
  9.  
  10.     public static void main( String[] args ) throws Exception {
  11.         JChannel channel = new JChannel( "UDP(bind_addr=127.0.0.1)" );
  12.         channel.setReceiver( new ReceiverAdapter() {
  13.  
  14.             @Override
  15.             public void receive( Message m ) {
  16.                 System.out.println( m.getObject() );
  17.             }
  18.  
  19.         } );
  20.         channel.connect( "MyCluster" ); // ÐŸÐ¾Ð´ÐºÐ»ÑŽÑ‡Ð°ÐµÐ¼ÑÑ Ðº Ð³Ñ€ÑƒÐ¿Ð¿Ðµ
  21.  
  22.         /**
             * Ð¦Ð¸ÐºÐ» Ð¾Ð±Ñ€Ð°Ð±Ð¾Ñ‚ки ÐºÐ¾Ð¼Ð°Ð½Ð´ Ñ ÐºÐ¾Ð½ÑÐ¾Ð»Ð¸
             */
  23.         BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
  24.         while ( true ) {
  25.  
  26.             String line = in.readLine();
  27.  
  28.             if ( line.equalsIgnoreCase( "quit" ) || line.equalsIgnoreCase( "exit" ) ) {
  29.                 break;
  30.             }
  31.  
  32.             channel.send( new Message( null, null, line ) );
  33.         }
  34.  
  35.         channel.close(); // ÐžÑ‚ключаемся Ð¾Ñ‚ Ð³Ñ€ÑƒÐ¿Ð¿Ñ‹ Ð¿Ð¾ Ð·Ð°Ð²ÐµÑ€ÑˆÐµÐ½Ð¸ÑŽ Ñ€Ð°Ð±Ð¾Ñ‚Ñ‹
  36.     }
  37.  
  38. }

Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2017