inject.java

来自「利用hashtable实现网络广播」· Java 代码 · 共 44 行

JAVA
44
字号
import java.util.*;import java.net.*;import java.io.*;public class Inject {  public static void main( String [] args ) {    int port = 0;    String msg, st, host;    Socket s;    int len;    OutputStream out;    Scanner sc;    try {      if( args.length < 3 ) {        sc = new Scanner( System.in );        System.out.print( "Enter host to connect to: " );        host = sc.nextLine();        System.out.print( "Enter port to bind on: " );        port = sc.nextInt();        sc.nextLine();        System.out.print( "Enter message: " );        msg = sc.nextLine();      } else {        host = args[0];        port = Integer.parseInt( args[1] );        msg = args[2];      }      if( ( port < 1024 ) || ( port > 32767 ) ) {        System.out.println( "Bad port specified" );        return;      }          System.out.println( "Connecting to " + host + ":" + port );      s = new Socket( host, port );      Peer.write( s, "BCAST NAP " + Peer.BCAST_INIT + " " + msg );      s.close();    } catch ( Exception e ) {      System.out.println( e );    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?