java吧 关注:1,305,130贴子:12,869,211
  • 0回复贴,共1

我编java通讯程序

只看楼主收藏回复

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class server extends JFrame
{private static JFrame jf=new JFrame();
private static JTextField txt=new JTextField(20);
private static JButton bb=new JButton("发送");
public static void main(String[] args)
{
jf.setTitle("王云勇的信息服务器");
jf.setVisible(true);
jf.setSize(600,200);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setLayout(new FlowLayout());
jf.add(txt);jf.add(bb);
ServerSocket ss=null;
Socket s=null;
OutputStream out=null;
try{ss=new ServerSocket(20023);}
catch(IOException e) {System.out.println("错了");}
while(true)
{
try{s=ss.accept();out=s.getOutputStream();}
catch(IOException e) {System.out.println("错了");}
PrintStream ff=new PrintStream(out);
bb.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
{final String fs=new String(txt.getText());ff.println(fs);}});
}
}
}


IP属地:广东来自Android客户端1楼2017-10-24 23:58回复