黑马程序员技术交流社区
标题:
Socket
[打印本页]
作者:
sixth
时间:
2012-11-2 12:55
标题:
Socket
import java.io.*;
import java.net.*;
class Client
{
public static void main(String[] args) throws Exception
{
Socket s = new Socket("ip",10008);
BufferedReader bufr = new BufferedReader(new FileReader("Xxx.java"));
PrintWriter pwOut = new PrintWriter(s.getOutputStream(),true);
BufferedReader bufIn = new BufferedReader(new InputStreamReader(s.getInputStream()));
String str = null;
String line = null;
while((line=bufr.readLine())!=null)
{
pwOut.println(line);
}
s.shutdownOutput();
str = bufIn.readLine();
System.out.println("server:"+str);
bufr.close();
s.close();
}
}
class Server
{
public static void main(String[] args)throws Exception
{
ServerSocket ss = new ServerSocket(10008);
Socket s = ss.accept();
String ip = s.getInetAddress().getHostAddress();
System.out.println(ip+"....connected");
BufferedReader bufIn = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter pw = new PrintWriter(System.out,true);
String line = null;
while((line=bufIn.readLine())!=null)
{
pw.println(line);
}
PrintWriter pwOut = new PrintWriter(s.getOutputStream(),true);
String str = "上传成功";
pwOut.println(str);
pw.close();
s.close();
ss.close();
}
}
作者:
朱宏青
时间:
2012-11-2 13:03
删前留名
作者:
奋斗的青春
时间:
2012-11-2 13:17
这位童靴能说下是什么意图吗 ,
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2