2018.4.15 网络编程

//单纯的客户端服务端有个局限性,A客户端连接上以后,未处理完之前,B客户端连接只有等待
//所以服务端最好将每个客户端封装到一个线程中

class PicThread implements Runnable
{
 private Socket s;
 public PicThread(Socket socket) {
  // TODO Auto-generated constructor stub
  this.s = socket;
 }
 public void run() {
   int count =1;
   String ip = s.getInetAddress().getHostAddress();
  try {
   System.out.println(ip+"connect");
   InputStream in = s.getInputStream();
   FileOutputStream fos = new FileOutputStream("");
   
   byte[] buf = new byte[1024];
   int len = 0;
   while((len=in.read(buf))!=-1)
   {
    fos.write(buf,0,len);
   }
   OutputStream out = s.getOutputStream();
   
   out.write("上传成功".getBytes());
   
   fos.close();
   s.close();
  } catch (Exception e) {
   // TODO: handle exception
   throw new RuntimeException("上传失败");
  }
 }
 
}
//windows上远程登陆命令 telnet IP Port
客户端服务端可进行:

    1
    客户端:浏览器(telent)
    服务端:自定义
    2
    客户端:浏览器
     服务端:tomcat服务器       
URLConnection
//Sorket是在传输层进行,而URLConnection可以通过URL对象的方法获取,通过InputStream方法,在应用层对其进行操作,
//自带拆http协议头的BGM

//InetSorketAddress包括IP地址和端口
域名解析
    //先走本地在联网搜索,联网搜索时若搜索的为主机名,则去默认DNS中解析出IP,再去搜索

    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值