Logcat:java.net.bindexception address already in use console:jav

Fermé
pfe201513 Messages postés 1 Date d'inscription lundi 16 mars 2015 Statut Membre Dernière intervention 16 mars 2015 - 16 mars 2015 à 14:16
logcat:java.net.bindexception address already in use. at libcore.io.iobridge.blind

console: java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

i want to send my file apk from server java to client android in the localhost main activity in my android application:

public class MainActivity extends Activity implements OnClickListener { public static String ism;
@Override
public void onClick(View v) {
Initial_historique.lance();

}
});


btnNavigator.setOnClickListener(new OnClickListener() {

//button pour recevoire le .apk appel socket
@Override
public void onClick(View arg) {
// TODO Auto-generated method stub

new Thread(new Runnable() {
@Override
public void run() {

try {
SocketFromServer.soc();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}).start();


//appel au thread pour recevoire

}
});
}
}

my class socket in the android application:

public class SocketFromServer
{
public static void soc() throws IOException
{
Socket sock = new ServerSocket(9001).accept();

Commun.transfert(
sock.getInputStream(),
new FileOutputStream("/data/data/com.so.and/And1.apk"),
true);

sock.close();
}
}


my main in java application:

public class Serveur
{


public static void main(String[] args) throws IOException, InterruptedException
{
SocketToClient.socket();

}
}


my class socket in my java application:


public class SocketToClient
{
public static void socket() throws IOException
{
Socket sock = new Socket("10.0.2.2",9001);

Commun.transfert(
new FileInputStream("C:/Users/admin/Desktop/ws/serveur/And.apk"),
sock.getOutputStream(),
true);

sock.close();
}
}


public  class Commun extends SocketToClient
{
public static void transfert(InputStream in, OutputStream out, boolean closeOnExit) throws IOException
{
byte buf[] = new byte[1024];

int n;
while((n=in.read(buf))!=-1)
out.write(buf,0,n);

if (closeOnExit)
{
in.close();
out.close();
}
}
}