?? sendtcp.java
字號:
/**************************************************
*copyright(c) 2007-2008 HBUT WUHAN
*FILE_NAME:SendTCP.java
*Author:楊慜 0412002225 Major:計算機科學與技術
*Version:1.0 Date:2008-01-09
*Description:發送TCP數據包的發送端程序
*Function List:
**************************************************/
import java.net.*;
import java.io.*;
public class SendTCP
{
public static void main(String[] args) throws IOException
{
if (args.length!=4)
{
System.out.println("您在命令行的輸入格式有誤,請按照以下格式重新輸入!");
System.out.println("源IP地址 源端口 目的IP地址 目的端口");
System.exit(0);
}
String source_ip=args[0];
int source_port=Integer.parseInt(args[1]);
String dest_ip=args[2];
int dest_port=Integer.parseInt(args[3]);
if (dest_port!=10000)
{
System.out.println("請保持目的端口為10000!");
System.exit(0);
}
OutputStream os=null;
PrintStream ps=null;
BufferedReader bf=null;
String message="This is my homework of network!";
Socket soc=null;
try{
soc=new Socket(dest_ip,dest_port);
System.out.println("***************************************************");
System.out.println("Connect to server......");
System.out.println("***************************************************");
System.out.println();
bf=new BufferedReader(
new InputStreamReader(System.in));
System.out.print("Please input the message: ");
message=bf.readLine();
os=soc.getOutputStream();
ps=new PrintStream(os);
ps.println(message);
bf.close();
ps.close();
os.close();
System.out.println();
System.out.println("***************************************************");
System.out.println("Send OK !");
System.out.println("The message was send to the address: "+dest_ip+"["+dest_port+"]");
System.out.println("***************************************************");
soc.close();
}catch(Exception e)
{
System.out.println(e);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -