다른 사람과 마찬가지로 서버 소켓을 수락하여 해결할 수 없습니다. ? (잠금 영원히에, 나는 SS없이이 문제를 해결하려면 어떻게] 아래에 의견을알 수없는 호스트 예외 오류 [중복되지 않음]
import java.net.*;
import java.io.*;
public class one_hundred
{
public static void main(String [] args)
{
String hostName = "pool-72-83-252-59.washdc.fios.verizon.net";
int portNumber = 3281;
try
{
/*
Open a socket.
Open an input stream and output stream to the socket.
Read from and write to the stream according to the server's protocol.
Close the streams.
Close the socket.
*/
Socket server = new Socket(hostName, portNumber);
OutputStream outToServer = server.getOutputStream();
DataOutputStream out = new DataOutputStream(outToServer);
out.writeUTF("mJFr1vJBIcpYTtIui6yLrzQw " + server.getLocalSocketAddress());
InputStream inFromServer = server.getInputStream();
DataInputStream in = new DataInputStream(inFromServer);
System.out.println(in.readUTF());
server.close();
}catch(IOException e)
{
e.printStackTrace();
}
}
}
를 참조 (또는 어떻게 든 소켓 잠금하는 문제를 해결
이 또한 실패에 대한 대안 시도 :
import java.io.*;
import java.net.*;
import java.net.Socket;
public class onehundred
{
public static void main(String args[]) throws java.io.IOException
{String urlParameters = "fName=" + URLEncoder.encode("???", "UTF-8") + "&lName=" + URLEncoder.encode("???", "UTF-8");
request("http://codeabbey.sourceforge.net", urlParameters);}
public static String request(String gotourl, String urlParameters)
{ HttpURLConnection connection = null;
try
{ InetAddress locIP = InetAddress.getByName("0.0.0.0");
ServerSocket serverSocket = new ServerSocket(8080, 0, locIP);
//Create connection
URL url = new URL(gotourl);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("/say-100.php", "Token: 9PaF2QQmZBFX+K3+LlI5ozky");
connection.setUseCaches(false);
connection.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream (connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.close();
//Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
StringBuilder response = new StringBuilder();
String line;
while((line = rd.readLine()) != null)
{ response.append(line);
response.append('\r');
}
rd.close();
System.out.println(response); //System.out.println(line); also prints out nothing
return response.toString();
} catch (Exception e)
{e.printStackTrace();
return null;
} finally
{
if(connection != null)
{connection.disconnect();}
}
}
}
을?
오류 메시지는 문제가 무엇인지 말합니다. 어떤 유형이 필요한지 * ([documentation] (https://docs.oracle.com/javase/8/docs/api/java/net/ServerSocket.html) 참조))? 어떤 유형이 제공됩니까? 제공된 -> 필요한 "논리"방법 있는가? – user2864740
명백히'accept()'는 정적 메서드입니다. 따라서 클래스 자체가 아니라 ServerSocket의 인스턴스에서 메서드를 호출해야합니다. – RobotKarel314