1) 권한 추가 "AndroidManifest.xml"

  "<uses-permission android:name="android.permission.INTERNET"/>"

 

2) Socket 생성은 Thread에서 생성한다. (onCreate()나 Main Process에서 만들면 Error발생.)

private Thread InitSocket = new Thread() {
    public void run() {
    try {
        socket = new Socket(ip, port); //<<========이런 식으로.
    } catch (IOException e1) {
        e1.printStackTrace();
    }
};

 OnCreate()에서 CreateSocket.start();

 

 

 

*추가 : Host Name으로 접속 시도

Socket socket = new Socket();

InetSocketAddress address = new InetSocketAddress("SW_CCH", 8500);

socket.connect(address);

+ Recent posts