我用java写了一个简单的服务器程序,用来模拟一个服务器(我没有原来的服务器程序,只能模拟)。ServerSocket=new ServerSocket(2022,10);
Socket client=ServerSocket.accept();
然后获得一个DataInputStream in 和PrintWriter对象
然后 byte [] t=new byte[];in.read(t);
到read的时候就不走了 
可是我用自己写的客户端却可以数据,晕死,指点一下,老大们!注明:这里的客户端不是用JAVA写的,什么语言写的不清楚,估计是C++

解决方案 »

  1.   

    socket通信与用何种语言应该无关的。
    我这有个曾做过的Server端的例子,你看看import java.net.ServerSocket;
    import java.net.Socket;
    import java.io.*;public class ServerSocketIns{
    private String receiveMsg = "";
    private String sendMsg = "";

    public void doListener(int port){
    try{
    //build connection
    ServerSocket server = new ServerSocket(port);
    Socket socket = server.accept();
    System.out.println( "The server is listenning!" + "\n" ) ;

      while(true){
    //receive  message
    InputStream in = socket.getInputStream();
      this.receiveMsg = "" ;
    int ch ;
    while (true){        
              ch = in.read();
                 if ((char)ch == '\r')
                    break;
                 else 
                    this.receiveMsg += (char) ch;
              }
             
              if ( this.receiveMsg.equals( "Quit" ) )   // when quit
    System.exit(0); System.out.println("Receive from The Client :" + this.receiveMsg + "\n" );

    this.sendMsg = this.receiveMsg ;

    //send message
    OutputStream out = socket.getOutputStream();
    this.sendMsg += "  at Time: " ;
    this.sendMsg += (new java.util.Date()).toString();
    this.sendMsg += '\r' ;
    out.write( this.sendMsg.getBytes() );
    out.flush();
    System.out.println("The server has resended the message back!" );
    System.out.println(this.sendMsg);
    System.out.println();
      this.sendMsg = "" ;
      }
    }
    catch(IOException e){
    e.printStackTrace();
    }
    catch(Exception e){
    e.printStackTrace();
    }
    }

    public static void main(String[] args){
    ServerSocketIns ssocket = new ServerSocketIns() ;
    ssocket.doListener( 8000 ) ;
    }

    }
      

  2.   

    呵呵
    分嘛,小case啦
    关键是问题要解决ye