资源简介

sokect通讯例子--广播 包含客户端 服务器的完整示例

资源截图

代码片段和文件信息



import java.io.*;
import java.net.*;

/**
 * 发布广播
 * @author Wing
 *
 */
public class Client {
Socket socket;
BufferedReader in;
PrintWriter out;
BufferedReader line;
public Client() throws IOException {
try {
socket = new Socket(“127.0.0.1“ 10000);
in = new BufferedReader(new InputStreamReader(socket
.getInputStream()));
out = new PrintWriter(socket.getOutputStream() true);
line= new BufferedReader(new InputStreamReader(
System.in));
out.println(System.currentTimeMillis());
for (int i = 0;true; i++) {
out.println(line.readLine());
}

} catch (IOException e) {
}
finally{
line.close();
out.close();

in.close();
socket.close();
}
}

public static void main(String[] args) {
try {
new Client();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-07-29 20:46  Client\
     文件         232  2011-07-29 20:46  Client\.classpath
     文件         388  2011-07-29 20:46  Client\.project
     目录           0  2011-07-31 19:23  Client\bin\
     文件        1677  2011-07-31 20:03  Client\bin\Client.class
     文件        1893  2011-07-31 20:05  Client\bin\UserClient.class
     目录           0  2011-07-31 19:23  Client\src\
     文件         926  2011-07-31 20:02  Client\src\Client.java
     文件        1091  2011-07-31 20:05  Client\src\UserClient.java
     目录           0  2011-07-29 20:18  HelloSocket\
     文件         362  2011-07-29 20:18  HelloSocket\.classpath
     目录           0  2011-07-29 20:18  HelloSocket\.myeclipse\
     文件         306  2011-07-29 20:18  HelloSocket\.mymetadata
     文件        1201  2011-07-29 20:18  HelloSocket\.project
     目录           0  2011-07-29 20:18  HelloSocket\.settings\
     文件         500  2011-07-29 20:18  HelloSocket\.settings\.jsdtscope
     文件          49  2011-07-29 20:18  HelloSocket\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2011-07-29 20:18  HelloSocket\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2011-07-29 20:27  HelloSocket\src\
     目录           0  2011-07-29 20:27  HelloSocket\src\com\
     目录           0  2011-07-29 20:27  HelloSocket\src\com\wing\
     目录           0  2011-07-31 18:31  HelloSocket\src\com\wing\test\
     文件        3594  2011-07-31 20:03  HelloSocket\src\com\wing\test\Server.java
     目录           0  2011-07-29 20:18  HelloSocket\WebRoot\
     文件         834  2011-07-29 20:18  HelloSocket\WebRoot\index.jsp
     目录           0  2011-07-29 20:18  HelloSocket\WebRoot\meta-INF\
     文件          36  2011-07-29 20:18  HelloSocket\WebRoot\meta-INF\MANIFEST.MF
     目录           0  2011-07-29 20:18  HelloSocket\WebRoot\WEB-INF\
     目录           0  2011-07-29 20:27  HelloSocket\WebRoot\WEB-INF\classes\
     目录           0  2011-07-29 20:27  HelloSocket\WebRoot\WEB-INF\classes\com\
     目录           0  2011-07-29 20:27  HelloSocket\WebRoot\WEB-INF\classes\com\wing\
............此处省略6个文件信息

评论

共有 条评论