Android FTP Server

孤街醉人 提交于 2019-12-02 21:21:34

Maybe because you didn't set up the permissions in the manifest? You've to set permission for internet usage.

If this doesn't work, please tell us which line is it throwing the exception.

while(true){ incoming = s.accept(); ...} You cannot put that in OnStart(). That should be done in a thread. So ServerSocket s = null; should be a variable of you activity.

Using the Swiftp application (open source) as a service in my application helped me to acheive my task. Thanks for everyones help. Here is the link if someone wants to follow

You can not do network operation in main thread in android 3.0 higher. Use AsyncTask for this network operation. See this for further explanation

Raghunandan

Please post your code here.

NetworkOnMainthreadException occurs because you maybe running Network related operation on the Main UI Thread. You should use asynctask for this purpose

This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it's heavily discouraged.

http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html

class TheTask extends AsyncTask<Void,Void,Void>
{
protected void onPreExecute()
  {           super.onPreExecute();
             //display progressdialog.
  }  

protected void doInBackground(Void ...params)//return result here
{  
//http request. do not update ui here
//call webservice
//return result here
return null;
 } 

protected void onPostExecute(Void result)//result of doInBackground is passed a parameter
{     
    super.onPostExecute(result);
    //dismiss progressdialog.
    //update ui using the result returned form doInbackground()
} 
}

http://developer.android.com/reference/android/os/AsyncTask.html. Check the topic under the heading The 4 Steps.

A working example of asynctask @ To use the tutorial in android 4.0.3 if had to work with AsynxTasc but i still dont work?.

The above makes a webserive call in doInBakckground(). Returns result and updates the ui by setting the result in textview in onPostExecute().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!