📄 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 + -