Android Open Source - android-qq File Tcp Client






From Project

Back to project page android-qq.

License

The source code is released under:

Apache License

If you think the Android project android-qq listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.myandroid.util;
//from w w w  .j  a  v a  2  s. co m
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.Socket;
public class FileTcpClient {
  Msg msg = null;
  String path = null;

  public FileTcpClient(Msg msg, String path) {
    this.msg = msg;
    this.path = path;
  }

  public void start() {
    Client c = new Client();
    c.start();
  }

  class Client extends Thread {

    public void run() {
      try {
        creatClient();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

  public void creatClient() throws Exception {
    Socket s = new Socket(msg.getSendUserIp(), 2222);
    // ?????
    File file = new File(path);
    BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
    BufferedOutputStream os =new BufferedOutputStream( s.getOutputStream());
    // ?????
    double n = 1;
    byte[] data = new byte[Tools.byteSize];// ???????????
    int len=-1;
    while ((len=is.read(data))!= -1) {
      os.write(data,0,len); 
      Tools.sendProgress+=len;//????
    }
    Tools.sendProgress=-1;
    is.close();
    os.flush();
    os.close();
  }
}




Java Source Code List

com.myandroid.activity.ChatActivity.java
com.myandroid.activity.FileAcitivity.java
com.myandroid.activity.MainActivity.java
com.myandroid.activity.MediaDialog.java
com.myandroid.activity.SettingDialog.java
com.myandroid.util.Audio.java
com.myandroid.util.FileTcpClient.java
com.myandroid.util.FileTcpServer.java
com.myandroid.util.MediaTcpClient.java
com.myandroid.util.MediaTcpServer.java
com.myandroid.util.Media.java
com.myandroid.util.Msg.java
com.myandroid.util.Tools.java
com.myandroid.util.User.java