帮你up,VC懂一点没看出问题,Java网络编程不太懂,up!

解决方案 »

  1.   

    谢谢。java段的程序和java段的客户端,使用正常……呜呜。
      

  2.   

    BufferedReader换成DataInputStream这种方式试一试!
      

  3.   

    看看thinking in enterprise java
    java socket服务器和客户端都必须是java的
      

  4.   

    strongsoft((沈阳)) :
    换过去了。还是不行。
      

  5.   

    yoken(雨泉) :
    确定吗?确定的话,我要哭了。
      

  6.   

    to yoken:
    不是吧,我们做的是vc的服务端,java客户端,一点问题都没有啊,
    不过java服务端,vc客户端我没做过,没发言权
      

  7.   

    wnc() :
    谢谢你给我信心。我继续努力。java端发给vc端不会出现这个问题,能够一条接一条的读出来。
    倒过来,把我郁闷住了。
      

  8.   

    我簡單看了你的程序,不知道說的對不對,你在send的數據後面加上\r\n試一試。
    int k=connect(cliSocket,(sockaddr*)&cli,sizeof(cli));
    if(k==0){
    AfxMessageBox("spsheep2003");
    send(cliSocket,buff,sizeof(buff),0);
    }
    else 
    AfxMessageBox("failed");
    ......
    char buff[100]="something/r/n";
      

  9.   

    public void run() {
            try{
                 while(true)
                 {
                     out.println("123456");
                     str=in.readLine();
                     out.println("123456");
                     if(str.equals("end")) break;
                     System.out.println(str);
                     System.out.flush ();
                 }
            } catch ( Exception e ){}
    finally{
                try {
    if(sockrt!=NULL){socket.close();
    socket=null;}
            }
      

  10.   

    可能是Java与VC使用Socket是输入输出流的字符编码方式不同所至。Java的Socket获得的InputStream和OutputStream中的最小读写单位是字节Byte(1Byte=8bit),可以是任何二进制数据,但经过你的BufferedReader和PrintWriter封装之后,就只能传输String了,而在Java中的String是16位(2Byte)的Unicode编码,而且还可能向流中输入输出了经UTF编码的字符串或其他编码后的字符串。建议你先阅读关于java.io.DataInputStream的文档(http://java.sun.com/j2se/1.4.2/docs/api/java/io/DataInputStream.html)然后参看DataInputStream.java和DataOutputStream.java的源码,位于%JAVA_HOME%\src.zip中在你弄清楚Java服务器端程序中是如何把一个字符串String变成Byte并输入输出到Socket后,你才能写出对应的VC客户端程序。
      

  11.   

    经过编码的Java字符串当然VC不能正确识别(输入/输出)。
    还是建议你阅读DataOutputStream的源码。摘自:
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStreamWriter.htmlpublic class OutputStreamWriter
    extends WriterAn OutputStreamWriter is a bridge from character streams to byte streams: Characters written to it are encoded into bytes using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted. Each invocation of a write() method causes the encoding converter to be invoked on the given character(s). The resulting bytes are accumulated in a buffer before being written to the underlying output stream. The size of this buffer may be specified, but by default it is large enough for most purposes. Note that the characters passed to the write() methods are not buffered. For top efficiency, consider wrapping an OutputStreamWriter within a BufferedWriter so as to avoid frequent converter invocations. For example:  Writer out
       = new BufferedWriter(new OutputStreamWriter(System.out));
     A surrogate pair is a character represented by a sequence of two char values: A high surrogate in the range '\uD800' to '\uDBFF' followed by a low surrogate in the range '\uDC00' to '\uDFFF'. If the character represented by a surrogate pair cannot be encoded by a given charset then a charset-dependent substitution sequence is written to the output stream. A malformed surrogate element is a high surrogate that is not followed by a low surrogate or a low surrogate that is not preceeded by a high surrogate. It is illegal to attempt to write a character stream containing malformed surrogate elements. The behavior of an instance of this class when a malformed surrogate element is written is not specified.