//: JabberServer.java
// Very simple server that just
// echoes whatever the client sends.
import java.io.*;
import java.net.*;public class JabberServer {  
  // Choose a port outside of the range 1-1024:
  public static final int PORT = 8080;
  public static void main(String[] args) 
      throws IOException {
    ServerSocket s = new ServerSocket(PORT);
    System.out.println("Started: " + s);
    try {
      // Blocks until a connection occurs:
      Socket socket = s.accept();
      try {
        System.out.println(
          "Connection accepted: "+ socket);
        BufferedReader in = 
          new BufferedReader(
            new InputStreamReader(
              socket.getInputStream()));
        // Output is automatically flushed
        // by PrintWriter:
        PrintWriter out = 
          new PrintWriter(
            new BufferedWriter(
              new OutputStreamWriter(
                socket.getOutputStream())),true);
        while (true) {  
          String str = in.readLine();
          if (str.equals("END")) break;
          System.out.println("Echoing: " + str);
          out.println(str);
        }
      // Always close the two sockets...
      } finally {
        System.out.println("closing...");
        socket.close();
      }
    } finally {
      s.close();
    }
  } 
} ///

解决方案 »

  1.   

    协议有两种:TCP/IP和UDP,只用UDP的话,不能保证所有的用户可靠的收到信息,
    用TCP/IP的话肯定要有所有客户端的socket列表信息。
    有什么好的办法?
      

  2.   

    关于JAVA和VC端的通信有那位兄弟做过吗?
      

  3.   

    如果采用TCP/IP实现两端通信的话,我该怎么做啊?
      

  4.   

    cow...自己甚么都不知道还问个Ptcp/ip只是协议而已, 各种语言的开发都应该是一致的,
    关于具体两端怎么做,看书去 !