关于DELPHI 用SOCKET 发消息给JAVA,JAVA显示乱码的问题已用UTF-8但是还是解决不了。。。。。。。。。。
<p_extended="true">JAVA接收端代码如下:<p_extended="true">importjava.io.*;<br_extended="true"...
<p _extended="true">JAVA接收端代码如下:<p _extended="true">import java.io.*;<br _extended="true">import java.net.*;<p _extended="true">public class TestServer {<p _extended="true"> public static void main(String[] args) throws IOException{<br _extended="true">// TODO Auto-generated method stub<br _extended="true">ServerSocket server = new ServerSocket(1027);<br _extended="true">Socket client = server.accept();<br _extended="true">BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream(),"utf-8"));<br _extended="true">PrintWriter out = new PrintWriter(client.getOutputStream());<br _extended="true">while(true){<br _extended="true">//System.out.println("测试");<br _extended="true">out.println("接收...");<br _extended="true">String str = in.readLine(); <br _extended="true">System.out.println(str);<br _extended="true">out.flush();<br _extended="true">if (str.equals("hyd"))<br _extended="true">break;<br _extended="true">}<br _extended="true">client.close();<br _extended="true">server.close();<br _extended="true">}<p _extended="true">}<br _extended="true">DELPHI发送端代码如下:<p _extended="true">procedure TFormMain.btTestClick(Sender: TObject);<br _extended="true">var<br _extended="true"> ReqCode:array[0..2096] of char;<br _extended="true"> str: WideString;<br _extended="true">begin<br _extended="true"> //测试发送<br _extended="true"> try<br _extended="true"> ClientSocket.Host := Trim(127.0.0.1);<br _extended="true"> ClientSocket.Port := StrToInt(1027);<br _extended="true"> if not ClientSocket.Active then<br _extended="true"> ClientSocket.Open; <br _extended="true"> str := ‘CZ1\r\n许磊\r\nM\r\n29\r\n6\r\n’ ; <br _extended="true"> str := UTF8Encode(str);<br _extended="true"> StrPCopy(ReqCode,str);<br _extended="true"> ClientSocket.Socket.SendBuf(ReqCode,SizeOf(ReqCode)); <br _extended="true"> except<br _extended="true"> ON E:Exception do<br _extended="true"> Application.MessageBox(PChar('错误信息:' E.Message),'错误',MB_OK MB_ICONERROR);<br _extended="true"> end; <br _extended="true">end;<br _extended="true">谢谢各位了
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询