?? netipaddressdemo5.java
字號:
//Example 5 of Chapter 9
import java.net.*;
import java.io.*;
public class NetIpAddressDemo5 extends Thread
{
private static Socket socket;
public static void main( String[] args )
{
String hostname = "localhost";
int port = 65;
String s;
if( args.length > 1 )
{
hostname = args[0];
port = Integer.parseInt( args[1] );
}
try{
InetAddress hostaddress = InetAddress.getByName( hostname );
try{
socket = new Socket( hostaddress, port );
BufferedReader buf = new BufferedReader(
new InputStreamReader( socket.getInputStream( ) ) );
NetIpAddressDemo5 th = new NetIpAddressDemo5( );
th.start( );
while( ( s = buf.readLine( ) ) != null )System.out.println( s );
socket.close( );
}
catch( IOException e )
{
System.out.println( e.toString( ) );
}
}
catch( UnknownHostException e )
{
System.out.println( e.toString( ) );
}
}
public void run( )
{
String userInput;
BufferedReader buf;
PrintStream pstream;
try{
buf = new BufferedReader( new InputStreamReader( System.in ) );
pstream = new PrintStream( socket.getOutputStream( ) );
while( true )
{
if( socket.isClosed( ) ) break;
userInput = buf.readLine( );
pstream.println( userInput );
}
}
catch( IOException e )
{
System.out.println( e.toString( ) );
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -