经过编码的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.
java socket服务器和客户端都必须是java的
换过去了。还是不行。
确定吗?确定的话,我要哭了。
不是吧,我们做的是vc的服务端,java客户端,一点问题都没有啊,
不过java服务端,vc客户端我没做过,没发言权
谢谢你给我信心。我继续努力。java端发给vc端不会出现这个问题,能够一条接一条的读出来。
倒过来,把我郁闷住了。
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";
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;}
}
还是建议你阅读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.