What I was trying to do:
I was trying to build a test app, for now, simply establishing connection between the app on Android phone (4.2.2)(as client) and a java application running on pc (windows 8)(as server) via sockets connection.
What I've done already:
I've made the programs for both client and server in java on pc and tested them positively (Connection got established).
The network:
Both my phone and pc are connected to wifi at my home.ipconfig on pc shows address 192.168.56.1 while on logging into router it shows address of my pc to be 192.168.0.108 (Probably I don't understand networking :P).
The code:
client(Android)
public void connectPC(View view)
{
try
{
clientSocket = new Socket("192.168.0.108",1025);
outstream = clientSocket.getOutputStream();
instream = clientSocket.getInputStream();
data_out = new DataOutputStream(outstream);
data_in = new DataInputStream(instream);
statusView.setText("Connected!");
}
catch (Exception e)
{
statusView.setText("Error: "+e.getMessage());
}
}
The Server:
import java.net.*;
import java.io.*;
public class ServerSide extends Thread
{
ServerSocket serverSocket;
public ServerSide(int port) throws IOException
{
serverSocket = new ServerSocket(1025);
serverSocket.setSoTimeout(10000);
}
public void run()
{
while(true)
{
System.out.println("Waiting for client on port : "+ serverSocket.getLocalPort());
Socket server;
try {
server = serverSocket.accept();
System.out.println("Connected to : " +server.getRemoteSocketAddress());
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
}
}
}
public static void main(String... args)
{
int port=6066;
try
{
Thread t = new ServerSide(port);
t.start();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
}
The Problem:- The connection simply doesn't establish, the catch block shows e.getMessage() as null.
PS I've tried 192.168.56.1 ip address too. And added uses permission in manifest file
Any help in this regard please..!