Android Open Source - android-qq Media 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;
/*ww w.  j a  v  a 2s  .  c  o  m*/
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.Socket;

public class MediaTcpClient {
  Msg msg = null;
  String path = null;

  public MediaTcpClient(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();
        // Tools.sendProgress=-1;
      } catch (Exception e) {
        // TODO Auto-generated catch block
        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;
//    long part = file.length() / Tools.byteSize;// ??????
//    long surplus = file.length() % Tools.byteSize;// ??????????
    byte[] data = new byte[1024*5];// ???????????
    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();
    //???????????????????
    Tools.out("???????");
  }
}




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