안드로이드 전화 클라이언트 및 PC로 서버를 사용하여 소켓을 사용하여 프로그램을 작성하려고 노력 중이며 양면 코드와 약간 수정 된 코드가 있지만, t 클라이언트 활동을 얻고 나는 acutally 말하는 프로그램을 얻는 방법을 모른다. 나는 기본적으로 양면 입력 텍스트를 가질 수 있고 그것을 보내고 다른 사람에게 보이도록 설정하고 싶다. 얼마나 많은 양의 stickler가 있는지 알고있다. 너희들은 질문을하기 위해 ... 어떻게 의사 소통을 할 수 있니?서버/클라이언트 안드로이드 PC 통신 문제
클라이언트 코드 서버 코드
import java.io.*;
import java.net.*;
/**
* Simple server using Java Sockets.
* @author Jonathan Engelsma (http://www.cis.gvsu.edu/~engelsma)
*
*/
public class Server {
/**
* @param args
*/
public static void main(String[] args) {
try {
// First we create a server socket and bind it to port 9999.
ServerSocket myServerSocket = new ServerSocket(9999);
// wait for an incoming connection...
System.out.println("Server is waiting for an incoming connection on host="
+ InetAddress.getLocalHost().getCanonicalHostName()
+ " port=" + myServerSocket.getLocalPort());
Socket skt = myServerSocket.accept();
// ok, got a connection. Let's use java.io.* niceties to read and write from the connection.
BufferedReader myInput = new BufferedReader(new InputStreamReader(skt.getInputStream()));
PrintStream myOutput = new PrintStream(skt.getOutputStream());
// attempt to read input from the stream.
String buf = myInput.readLine();
// if we got input, print it out and write a message back to the remote client..
if (buf != null) {
System.out.println("Server read: [" + buf + "]");
myOutput.print("got it");
}
// close the connection.
skt.close();
System.out.println("Server is exiting");
} catch (IOException ex) {
ex.printStackTrace();
System.out.println("Whoops, something bad happened! I'm outta here.");
}
}
}
충돌이 발생했을 때의 상황은 무엇입니까? 연결하려고하면 충돌이 발생합니까? 활동이 시작될 때? – Jbecwar
그것은 프로그램이 오류를 닫으려고했는데 에뮬레이터에서 런타임 오류 인 것 같습니다. –