all I've created simple android app which should connect to Python 3.6 server through socket and send data. It doesn't work. I've lost my mind checking what's not working. Could You help me?
Main Activity
public class Test extends AppCompatActivity {
public Button but1;
int Ra;
public void init(){
but1 = (Button)findViewById(R.id.button_id);
but1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Client Connection = new Client();
Connection.execute();
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.INTERNET},Ra);
init();
}}
Second file
public class Client extends AsyncTask<Void ,Void , Void > {
@Override
protected Void doInBackground(Void... voids)
{
final String adress = "192.168.1.3";
final int Port = 70;
Log.d("Connection","trying to create connection");
try {
Log.d("Connection", "Creating socket");
Socket connect = new Socket(adress, Port);
Log.d("Connection","Connected");
DataOutputStream dout = new DataOutputStream(connect.getOutputStream());
DataInputStream din = new DataInputStream(connect.getInputStream());
dout.writeUTF("Hello");
dout.flush();
Log.d("Connection","Sent");
dout.close();
din.close();
connect.close();
}catch (IOException e){
{
e.printStackTrace();
Log.d("connection",e.getMessage());
}}
return null;
}}
Python server
import socket
_Connection = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#Creating socket
#binding socket to port
_ADDRESS = ('localhost', 70)
print('Starting Server on {} port {}'.format(*_ADDRESS))
_Connection.bind(_ADDRESS)
_Connection.listen(1)
while True:
conn, addr = _Connection.accept()
print("Connection from ", addr)
msg = _Connection.recv(1024)
print(msg)
Log
08-24 17:31:43.950 32614-1203/com.example.marcin.tcpiptest D/connection: failed to connect to /192.168.1.3 (port 70) from /:: (port 47696): connect failed: ETIMEDOUT (Connection timed out)
if anybody knows, what does I'm doing wrong and they would tell me, I would be grateful