-1
저는 Java에서 TCP/IP
으로 작업 중입니다. 먼저 TCP/IP
을 읽고 어떻게 작동하는지 이해합니다.
내가 원하는 항목 : -
자, 이제 자바로 구현하고 싶습니다. 내 IP에서 특정 port/IP
요청에 일부 입력을 보내려고 노력하고 있습니다. 응답을 받아야합니다.
구현 방법을 모르겠습니다.TCP/IP 요청 보내기 및 응답 받기
Destination IP
Destination Port
Input(String or Anything)
여기 내가 클라이언트에 사용하는 내 코드입니다 :
여기 내 입력입니다.
try {
socket = new Socket("localhost", port);
}
catch(Exception e) {
System.out.println("Error connectiong to server:" + e);
return;
}
System.out.println("Connection accepted " +
socket.getInetAddress() + ":" +
socket.getPort());
/* Creating both Data Stream */
try
{
Sinput = new ObjectInputStream(socket.getInputStream());
Soutput = new ObjectOutputStream(socket.getOutputStream());
}
catch (IOException e) {
System.out.println("Exception creating new Input/output Streams: " + e);
return;
}
// now that I have my connection
String test = "aBcDeFgHiJkLmNoPqRsTuVwXyZ";
// send the string to the server
System.out.println("Client sending \"" + test + "\" to serveur");
try {
Soutput.writeObject(test);
Soutput.flush();
}
catch(IOException e) {
System.out.println("Error writting to the socket: " + e);
return;
}
// read back the answer from the server
String response;
try {
response = (String) Sinput.readObject();
System.out.println("Read back from server: " + response);
}
catch(Exception e) {
System.out.println("Problem reading back from server: " + e);
}
try{
Sinput.close();
Soutput.close();
}
제발 나에게 약간의 암시 또는 참고를주세요.
"작업 중"이라는 제목을 지정했지만 코드를 표시하지 마십시오. 그런 다음 "Ok, 이제 java로 구현하고 싶습니다."라고 씁니다. 그래서 : 무슨 일 이니? – TheBlastOne
UDP 또는 원시 소켓 (순수 IP)을 사용하는 경우 분실 패킷에 대해서만 걱정할 필요가 있습니다. TCP를 사용할 때 기본 프로토콜에 의해 처리되는 것은 모두 (재전송, 시간 초과, 핸드 셰이크)입니다. –
이 질문은 간단합니까? 아침부터 나는 TCP/IP를 이해하려고 노력 중이고 하나의 예를 시도하지만 그것은 나를 만족시키지 못했다. 나는 많은 노력을 기울인다. 왜 -1 표를 얻었 느냐 ... –