Dark Horse Programmer "" Java Learning path--TCP (iii) client uploads files to the server

Source: Internet
Author: User

-------<a href= "http://www.itheima.com" target= "blank" >android training </a> <a href= "/http/ Www.itheima.com "target=" blank ">java training </a>, look forward to communicating with you! ----------

Import java.io.*;

Import java.net.*;
Class Textclient
{
public static void Main (string[] args) throws Exception
{
Socket s = new socket ("192.168.1.104", 10010);
BufferedReader BUFR =
New BufferedReader (New FileReader ("Tcpdemo.java"));
PrintWriter out = new PrintWriter (S.getoutputstream (), true);


String line = null;
while (line = Bufr.readline ())!=null)
{
Out.println (line);
}
S.shutdownoutput ();//close the client output stream, which is equivalent to adding an end tag to the stream (mode two)
Out.println ("over");//Custom end tag (end mode one)
BufferedReader Bufin = new BufferedReader (New InputStreamReader (S.getinputstream ()));
String str = bufin.readline ();
System.out.println (str);
Bufr.close ();
S.close ();
}
}
Class Textserver
{
public static void Main (string[] args) throws Exception
{
ServerSocket ss = new ServerSocket (10010);
Socket s = ss.accept ();
String IP = s.getinetaddress (). gethostaddress ();
System.out.println (ip+ "... connected");
DataInputStream dis = new DataInputStream (S.getinputstream ());
Long L = Dis.readlong ();


BufferedReader Bufin = new BufferedReader (New InputStreamReader (S.getinputstream ()));
PrintWriter out = new PrintWriter (New FileWriter ("Server.txt"), true);
String line = null;
while (line = Bufin.readline ())!=null)
{
if ("Over". Equals (line))
{
Break
}//Custom end tag (end mode one)
Out.println (line);
}


PrintWriter pw = new PrintWriter (S.getoutputstream (), true);
Pw.println ("Upload success");
Out.close ();
S.close ();
Ss.close ();

}
}







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.