现在的位置: 首页 > 综合 > 正文

用socket实现的文件服务器(1)

2013年07月06日 ⁄ 综合 ⁄ 共 1095字 ⁄ 字号 评论关闭
public class ForumFileClient
{
    static InetAddress addr;
    static
    {
        try
        {
            addr=InetAddress.getByName("127.0.0.1");
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    private Socket socket;
    private BufferedReader in;
    private PrintWriter out;
   
    public ForumFileClient()
    {
        try
        {
            socket=new  Socket(addr,ForumFileServer.PORT);
            in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
            out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    public void closeSocket()
    {
        try
        {
            socket.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    /**
     * @return Returns the in.
     */
    public BufferedReader getIn()
    {
        return in;
    }
    /**
     * @return Returns the out.
     */
    public PrintWriter getOut()
    {
        return out;
    }
    /**
     * @return Returns the socket.
     */
    public Socket getSocket()
    {
        return socket;
    }
   
}

抱歉!评论已关闭.