📄 96.html
字号:
<br>Return; <br><br>} <br><br>this.start; <br><br>} // End of Connection method <br><br>// 服务例程:读出一行文本;反转文本;返回文本。 <br><br>public void run() <br><br>{ <br><br> String line; <br><br> StringBuffer revline; <br><br>int len; <br><br> try <br><br>{ <br><br> for(;;) <br><br>{ <br><br> // Read a line <br><br> line = in.readline(); <br><br> if(line == null) break; <br><br> // Reverse the line <br><br> len = line.length(); <br><br> revline = new StringBuffer(len); <br><br> for(int i = len-1; i >=0; i--) <br><br> revline.insert(len-1-I;line.charAt(i)); <br><br> // Write out the reverse line <br><br> out.println(revline); <br><br> } <br><br>catch(IOException e); <br><br>finally try client.close(); <br><br>catch(IOException e2); <br><br>} <br><br>// End of run method <br><br>} <br><br>// End of Connection class <br><br>3、编写客户机类Java 程序 <br><br>// Client.java <br><br>import java.io.*; <br><br>import java.net.*; <br><br>public class Client extends <br><br>{ <br><br> public static final int Default_Port = 6543; <br><br>// 定义出错例程 <br><br> public static final void usage() <br><br> { <br><br> System.out.println("Usage: Java Client []"); <br><br> System.exit(0); <br><br>} <br><br> public static void main(String args[]) <br><br>{ <br><br> int port = Default_Port; <br><br>Socket s = null; <br><br>// 解析端口参数 <br><br>if ((args.length != 1)&&(args.length != 2 )) usage(); <br><br>if (args.length == 1) <br><br> port = Default_Port; <br><br>else <br><br>{ <br><br> try port = Integer.parseInt(args[1]); <br><br> catch(NumberFormaatException e) usage(); <br><br>} <br><br>try{ <br><br> // 产生一个Socket ,通过指定的端口与主机通信。 <br><br> s = new Socket(args[0], port); <br><br>// 产生用于发出和接收的文本字符流 <br><br>DataInputStream sin = new DataInputStream(s.getInputStream()); <br><br>PrintStream sout = new DataInputStream(s.getInputStream()); <br><br>// 从控制台读入字符流 <br><br>DataInputStream in = new DataInputStream(System.in); <br><br> // 返回连接的地址和端口 <br><br>System.out.println("Connected to"+s.getInetAddress()+":"+ s.getPort()); <br><br> String line; <br><br> For(;;) <br><br> { <br><br> // 显示提示符 <br><br> System.out.print(" >"); <br><br> System.out.flush(); <br><br> // 读入控制台输入的一行字符 <br><br> line = in.readline(); <br><br> if (line == null) break; <br><br> // 将接收的文本行送至服务器 <br><br> sout.println(line); <br><br> // 从服务器接收一行字符 <br><br> line = sin.readline(); <br><br> // Check if connection is closed(i.e. for EOF) <br><br> if(line == null) <br><br> { <br><br> System.out.println("Connection closed by server."); <br><br> Break; <br><br>} <br><br> // 在控制台上显示接收的字符 <br><br> System.out.println(line); <br><br>} <br><br>// End of for loop <br><br>} <br><br>/ End of try <br><br>catch(IOException e ) System.err.println(e); <br><br>// Always be sure to close the socket <br><br>finally <br><br>{ <br><br> try if(s != null) s.close(); <br><br> catch(IOException e2); <br><br>} <br><br>} // End of main <br><br>} // End of Client <br><br>运行该客户机程序时,必须以服务器主机名作为第一个参数,服务器端口号为第二个参数, <br><br>其中服务器端口号可缺省。 <br></p></td>
</tr>
</table>
<p>
<CENTER><a href="http://www.jsp001.com/forum/newreply.php?action=newreply&threadid=96">点这里对该文章发表评论</a></CENTER>
<p>该文章总得分是 <font color=red>0</font> 分,你认为它对你有帮助吗?
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=96&intVote=4","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>非常多</a>](<font color=red>0</font>)
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=96&intVote=2","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>有一些</a>](<font color=red>0</font>)
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=96&intVote=1","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>无帮助</a>](<font color=red>0</font>)
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=96&intVote=-1","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>是灌水</a>](<font color=red>0</font>) </p>
<script language="javascript" src="http://www.jsp001.com/include/read_thread_script.php?threadid=96"></script>
<p><CENTER>
Copyright © 2001 - 2009 JSP001.com . All Rights Reserved <P>
<IMG SRC="../image/jsp001_small_logo.gif" WIDTH="85" HEIGHT="30" BORDER=0 ALT="">
</CENTER></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -