如何用J4V4来做编程

作者:张丽 | 原创 | 2008-05-11 01:36 | 投票
标签: 信息产业 
  newThreadEchoHandler(incoming,i).start();

  i++;

  }

  }

  catch(Exceptione)

  {System.out.println(e);}

  }

  }

  //客户端通信小应用程序Echo.java

  importjava.io.*;

  importjava.net.*;

  importjava.awt.*;

  importjava.applet.*;

  publicclassEchoextendsApplet

  {

  TextAreata;

  SocketechoSocket;

  DataOutputStreamos;

  DataInputStreamis;

  StringLine;

  publicvoidinit()

  {

  setBackground(Color.white);

  ta=newTextArea(5,80);

  ta.setEditable(false);

  add(ta);

  try

  {echoSocket=newSocket("10.102.4.41",1111);}//与服务器建立连接

  catch(IOExceptione)

  {System.out.println("error");}

  }

  publicvoidst(Stringstri)//发送字符串的方法

  {

  try

  {DataOutputStreamos=newDataOutputStream(echoSocket.getOutputStream());

  DataInputStreamis=newDataInputStream(echoSocket.getInputStream());

  os.writeUTF(""+stri);//向服务器输送string

  os.flush();

  }

  catch(IOExceptione)

  {System.out.println("error:"+e);}

  }

  publicStringst1()//接收字符串的方法

  {

 [1] [2] [3] [4] [5] [6] [7] 
个人简介
Baidu 广告
Google 广告