Java与Delphi通过Socket通信问题
java端
InetAddress addr = InetAddress.getByName( "192.168.0.199 ");
Socket socket = new Socket(addr, 3000);
try {
BufferedReader in =
new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
PrintWriter out =
new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
socket.getOutputStream())), true);
out.println(this.getSimNum());
String str = in.readLine();
if(str==null)
str= "无此SIM卡号 ";
return str;
}
finally {
socket.close();
}
}
delphi端
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
receiveText : string;
i: Integer;
begin
Form1.Edit1.Text := ' ';
receiveText := Socket.ReceiveText;
Form1.Edit1.Text := receiveText ;
for i:=0 to Form1.ServerSocket1.Socket.ActiveConnections-1 do
begin
Form1.ServerSocket1.Socket.Connections[i].SendText(ht.Get(simNum1));
form1.ServerSocket1.Socket.Connections[i].Close;
end;
end;
delphi端 serverSocket端口设置正确 在同一台机器上运行成功,分开两台机运行
delphi端得不到数据
谁知道为什么?
[解决办法]
ip 改了没
[解决办法]
代码没有问题,看看是不是防火墙的事,给拦截了。