服务器不通过套接字接受java中的客户端请求

时间:2017-09-22 17:03:59

标签: java sockets client-server

服务器"等待客户"和客户端向服务器发送请求,但服务器不接受客户端请求。 EchoServer.java

import java.net.ServerSocket;
import java.net.Socket;

public class EchoServer
{
    public static void main(String[] args) 
    {
        try 
        {
            System.out.println("Waiting for clients...");
            ServerSocket ss=new ServerSocket(9898);
            Socket soc=ss.accept();
            System.out.println("Connection established sucessfully");
        }
        catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

EchoClient.java

import java.net.Socket;

public class EchoClient
{
    public static void main(String[] args)
    {
        try 
        {
            System.out.println("Connection started");
            Socket soc=new Socket("localhost",9898);
        } 
        catch (Exception e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

我无法理解可能出现的问题,并提前致谢

0 个答案:

没有答案