文件名称:socket应用小程序
文件大小:6KB
文件格式:RAR
更新时间:2013-05-01 14:01:21
socket
几个很小的socket程序(源码)给其中一个小例: package cn.com.socket; import java.io.*; import java.net.*; public class ServerSocketThread extends Thread{ private Socket socket; private DataInputStream din; private DataOutputStream dout; public ServerSocketThread(Socket s){ socket = s; try{ din = new DataInputStream(socket.getInputStream()); dout = new DataOutputStream(socket.getOutputStream()); start(); }catch(IOException e){ System.out.println(e.getMessage()); } } public void run(){ String str; try{ System.out.println("连接成功"); System.out.println("******************************"); System.out.println(""); System.out.println("请等待客户发送信息......"); while(true){ BufferedReader sin = new BufferedReader(new InputStreamReader(System.in)); System.out.println(""); System.out.println(""); str = din.readUTF(); System.out.println("从客户接受的信息为:"+str); if(str.trim().equals("BYE")) break; System.out.println("请输入您要发送的信息:"); str = sin.readLine(); dout.writeUTF(str); dout.flush(); if(str.trim().equals("BYE")) break; } din.close(); dout.close(); socket.close(); }catch(IOException e){ System.out.println("Error: " + e); } } }
【文件预览】:
socket
----Server.java(2KB)
----ClientSocketThread.java(1KB)
----MultitalkServer.java(514B)
----ClientProgram.java(968B)
----TalkClient1.java(379B)
----ServerSocketThread.java(1KB)
----ServerProgram.java(2KB)
----Client.java(2KB)
----TalkClient2.java(379B)