Android Open Source - android-qq File Tcp Server






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  ww  .  j a v  a2s.co m*/
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import com.myandroid.activity.MainActivity;

import android.app.Activity;
import android.os.Message;

public class FileTcpServer {
  MainActivity mainA;

  public FileTcpServer(Activity mainA) {
    this.mainA = (MainActivity) mainA;
  }

  public void start() {
    server s = new server();
    s.start();
  }

  class server extends Thread {

    public void run() {
      try {
        creatServer();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }

  public void creatServer() throws Exception {
    ServerSocket ss = new ServerSocket(2222);
    Socket s = new Socket();
    s = ss.accept();
    File file = new File(Tools.newsavepath + "/" + Tools.newfileName);
    if (!file.exists()) {
      file.getParentFile().mkdirs();
      file.createNewFile();
    }
    BufferedInputStream is = new BufferedInputStream(s.getInputStream()); // ????
    BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));// ???
    Thread.sleep(1000);
    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();
    s.close();
    Tools.Tips(Tools.SHOW, "???????:"+Tools.newfileName);
  }
}




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