很抱歉,第十行代码打印错误.应该是:bind(myIP,6501);

解决方案 »

  1.   

    没有定义bind方法,必须先定义一个bind方法,才能用
      

  2.   

    回复sunlinux:
    bind所在的包是:java.net.ScoketImpl  我在前面有import java.net.*;
      

  3.   

    import java.io.*;
    import java.net.*;
    public class Class1
    {
    public void Bind()
    {
    try{
    InetAddress myIP=InetAddress.getLocalHost();
    Socket sock=new Socket(myIP,5720);
    bind(myIP,6501);
    }
    catch(UnknownHostException excpt)
    {
    System.err.println("Unknown host:"+excpt);
    }
    catch(IOException excpt)
    {
    System.err.println("I/O故障:"+excpt);
    }
    } /**
     * Method bind.
     * @param myIP
     * @param i
     */
    private void bind(InetAddress myIP, int i)
    {
    }}
    要定义bind方法;然后才去调用呀
      

  4.   

    可是bind是SocketImpl类中的方法啊.
      

  5.   

    建议你查看一下SocktImpl下面的bind方法如何来用
      

  6.   

    很抱歉我不就是知道SockImpl的bind如何用.(真笨!):)
      

  7.   

    bind()方法在SocketImpl中被申明为protected,当然不能直接调用啦!
    还有,想问一句,你学java多久?
    为什么对象还没定义,就拿着它的方法来用,先打好基础要紧哟!
      

  8.   

    试试Socket mysi = new SocketImpl()
    mysi.bind()
      

  9.   

    bind 在java.net.SocketImpl包中, 
    但是里面bind是声明为 protected abstract void bind(InetAddress host, int port) throws IOException 
    其中有abstract 所以你必须重新定义其方法的实现!有关java.net.SocketImpl的详细资料在这里:
    http://kbs.cs.tu-berlin.de/~jutta/ht/apibook/javaf7.htm#31923
      

  10.   

    **/import java.net.*;
    import java.io.*;public class Server
    {
    ServerSocket  server; 
    DataOutputStream   output;
    Socket  socket;
    public Server (){
    try{
         // create a server on port 5000
                    server=new ServerSocket(5000);
    // display interactive informaion
    System.out.println("Server created.");
    System.out.println("waiting for client to connect on...");
    // waiting for client to connect on...
    socket = server.accept();
                            // client connected
                            System.out.println("client connected.\nShutdown!");  
    output = new DataOutputStream(socket.getOutputStream());
    output.writeUTF("Welcome to Server.Bye!");
                            output.close();
    server.close();     
    }
    catch(SocketException e){
    System.out.println(e.toString());
    e.printStackTrace();
    System.exit(1);
    }
    catch(IOException e){
    System.out.println(e.toString());
    e.printStackTrace();
    System.exit(1);
    }
    }       public static void main(String args[]){
    Server game=new Server();
    }
    }server 端的程序;import java.io.*;
    import java.net.*;public class Client {      
           public static void main(String args[])   {
                    try{
    if (args.length != 1){
    System.out.println("USAGE: java Client servername");
    return;
    }
    String  connectto= args[0];
                            Socket connection;
    // connect to server
    if(connectto.equals("localhost")){
    connection=new Socket(InetAddress.getLocalHost(),5000); }
    else{
    connection=new Socket(InetAddress.getByName(connectto),5000);
    }
    DataInputStream  input=new DataInputStream(connection.getInputStream());                        // read information from server                        
                            String info;
                            info = input.readUTF();
                            System.out.println(info);
    connection.close();                                                               
    }
    catch(SecurityException e){
    System.out.println("SecurityException when connecting Server!");
    }
    catch(IOException e){
    System.out.println("IOException when connecting Server!");   
    }
           }}
    client端的程序;