public class MainActivity extends AppCompatActivity {
EditText editText_id;
EditText editText_password;
Socket socket = null;
ObjectInputStream ois = null;
ObjectOutputStream oos = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText_id = (EditText) findViewById(R.id.editText_id);
editText_password = (EditText) findViewById(R.id.editText_password);
}
public void onButtonLoginClicked(View v) { // 연결하기
ConnectTread thread = new ConnectTread();
thread.start();
// send_toServer("Login/"+editText_id.getText().toString()+"@"+
// editText_password.getText().toString());
try {
oos.writeObject(editText_password.getText().toString());
oos.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
// private void send_toServer(String msg){//Protocol : / 메시지: @
// try {
// oos.writeObject(msg);
// oos.flush();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// }
class ConnectTread extends Thread {
public void run() {
Myclient client = new Myclient();
client.connection();
}
}
private class Myclient {
String ip = "218.151.105.235";
int port = 5001;
String msg;
private void connection() {
try {
socket = new Socket(ip, port);
ois = new ObjectInputStream(socket.getInputStream());
oos = new ObjectOutputStream(socket.getOutputStream());
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
try {
oos.writeObject(editText_password.getText().toString());
oos.flush();
} catch (IOException e) {
e.printStackTrace();
}
이부분에서 ObjectOutputStream이 문제가 되네요.. 이와같이 작성한 비슷한 채팅 프로그램은 돌아가는데
왜안되는지 전혀 모르겠습니다 ㅠㅠ 이걸로 한 이틀 밤샌거같네요..