MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » 如何确定两台主机间是否互连

如何确定两台主机间是否互连(2)

www.MyException.Cn  网友分享于:2013-01-31  浏览:25次

add("Center",t_1);
}
}

class WindowClosing extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(1);
}
}



class server extends Thread
{
OutputStream os=null;
InputStream is=null;
static byte[] buf=new byte[100];
static String in="haha";
static int len=0;
private Socket s;
public server(Socket s)
{
this.s=s;
}
public void run()
{
try
{
os=s.getOutputStream();
is=s.getInputStream();
os.write("消息发送成功".getBytes());
len=is.read(buf);
System.out.println(new String(buf,0,len));
in="hehe";
Frame_Server.t_1.append(new String(server.in));
Frame_Server.t_1.append(new String(buf,0,len));
is.close();
os.close();
s.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void servers()
{
try
{
ServerSocket ss=new ServerSocket(6000);
while(true)
{
Socket s=ss.accept();
char[] buf=new char[100];
new server(s).start();
System.out.println("IP is:"+s.getInetAddress()+s.getPort());
String s_3=new String(buf,0,30);
System.out.println(s_3);
String s_s="hello you !";
Frame_Server.t_1.append(s_3);//new String(s_3));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}




Frame_Client.java 
Java code
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class Frame_Client extends Frame
{
static TextField t_1=new TextField(10);
static TextArea t_2=new TextArea();
public static void main(String args[])
{
socket_1.clients("Chat now!");
Frame_Client f=new Frame_Client("Frame_Client");
f.setSize(400,200);
f.setLocation(400,0);
f.setBackground(Color.pink);
f.dispose();
f.addMenu();
FA fa=new FA();
f.addWindowListener(fa);
f.setVisible(true);
}
public Frame_Client(String str)
{
super(str);
}
public void addMenu()
{
MenuBar mb=new MenuBar();
Menu file=new Menu("fiel");
MenuItem st=new MenuItem("start");
st.addActionListener(new MenuEvent());
file.add(st);
mb.add(file);
setMenuBar(mb);
}

public void dispose()
{
Panel p_1=new Panel();
Label l_1=new Label("请输入信息:");
p_1.add(l_1);
t_1.setEditable(true);
p_1.add(t_1);
add("North",p_1);
t_2.setEditable(false);
add("Center",t_2);
}

}
class FA extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(1);
}
}

class MenuEvent implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String str_1=Frame_Client.t_1.getText();
socket_1 s_1=new socket_1();
new socket_1().clients(str_1);
Frame_Client.t_2.append(new String(s_1.buf,0,s_1.len));

}
}

class socket_1
{
static OutputStream os=null;
static InputStream is=null;

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有