资源简介
计算机网络课程设计 高分作业 java实现
代码片段和文件信息
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.Jframe;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class host extends Jframe{
private static final long serialVersionUID = 1L;
public String DesAddress = new String(“aini“);
public String Data = new String(“ini“);
public String SouAddress = new String(“ini“);
public String[] routes= new String[6];
public int[] ports= new int[3];
public int port;
public String nextAddmyIP;
public JTextField jtf = new JTextField();
public JTextField jtf1 = new JTextField();
private DataInputStream FromServer;
private DataOutputStream ToServer;
public void SendMessage(String dataString desAddressString SouAddress) throws IOException{
for(int i=0;i<6;i=i+2){
if(routes[i].equals(desAddress)){
nextAdd=routes[i+1];
port=ports[i/2];
}
}
try {
Socket socket = new Socket(nextAddport);
ToServer = new DataOutputStream(socket.getOutputStream());
FromServer= new DataInputStream(socket.getInputStream());
} catch (UnknownHostException e) {
e.printStackTrace();
}
try {
ToServer.writeUTF(Data);
ToServer.writeUTF(DesAddress);
ToServer.writeUTF(SouAddress);
ToServer.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
public host(){
myIP =“192.168.0.1“;
routes[0]=“192.168.0.1“;
routes[1]=“192.168.0.1“;
routes[2]=“192.168.0.9“;
routes[3]=“192.168.0.9“;
routes[4]=“192.168.0.3“;
routes[5]=“192.168.0.3“;
ports[0]=8001;
ports[1]=8001;
ports[2]=8001;
JPanel p = new JPanel();
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
p.setLayout(new GridLayout(21));
p1.setLayout(new BorderLayout());
p2.setLayout(new BorderLayout());
p2.add(new JLabel(“Please Input Goal IP:“)BorderLayout.NORTH);
p2.add(jtf1BorderLayout.CENTER);
jtf1.setHorizontalAlignment(JTextField.LEFT);
p1.add(new JLabel(“Please Input What You Want to Send:“)BorderLayout.NORTH);
p1.add(jtfBorderLayout.CENTER);
jtf.setHorizontalAlignment(JTextField.LEFT);
p.add(p1);
p.add(p2);
setLayout(new BorderLayout());
add(pBorderLayout.CENTER);
jtf1.addActionListener(new ButtonListener());
settitle(“Host“);
setSize(500150);
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
setVisible(true);
}
public class ButtonListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent arg0) {
DesAddress=jtf1.getText();
Data=jtf.getText();
SouAddress=myIP;
try {
SendMessage(DataDesAddressmyIP)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-12-31 15:59 PCTYF\
文件 301 2014-06-19 16:40 PCTYF\.classpath
文件 378 2014-06-19 16:40 PCTYF\.project
目录 0 2014-12-31 15:59 PCTYF\.settings\
文件 598 2014-06-19 16:40 PCTYF\.settings\org.eclipse.jdt.core.prefs
目录 0 2014-12-31 15:59 PCTYF\bin\
文件 1126 2014-12-30 18:22 PCTYF\bin\host$ButtonListener.class
文件 3337 2014-12-30 18:22 PCTYF\bin\host.class
文件 449 2014-12-30 18:22 PCTYF\bin\Main.class
文件 3734 2014-12-30 18:22 PCTYF\bin\route.class
目录 0 2014-12-31 15:59 PCTYF\src\
文件 3089 2014-12-30 16:16 PCTYF\src\host.java
文件 118 2014-06-19 16:40 PCTYF\src\Main.java
文件 2769 2014-12-30 16:16 PCTYF\src\route.java
评论
共有 条评论