1
Javaアプリケーションファイルをソケットを使用して.Netアプリケーション(C#)に送信しようとしました。ここに私がやったことあるのJava(サーバ側)JavaからC#例外ファイルを送信しています
ServerSocket serverSocket = new ServerSocket(1592);
Socket socket = serverSocket.accept();
System.out.println("Connection accepted from " + socket);
PrintWriter out = new PrintWriter(socket.getOutputStream());
File file = new File("C:\\test.txt");
Thread.sleep(2000);
out.println(file.length());
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
OutputStream os = socket.getOutputStream();
byte[] bytes = new byte[(int) file.length()];
bis.read(bytes, 0, bytes.length);
os.write(bytes, 0, bytes.length);
C#の(クライアント)
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(ip, 1592);
using (var stream = tcpClient.GetStream())
using (var output = File.Create("result.txt"))
{
Console.WriteLine("Client connected. Starting to receive the file");
// read the file in chunks of 1KB
var buffer = new byte[1024];
int bytesRead;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)//(Exception caught here)
{
output.Write(buffer, 0, bytesRead);
}
私が持っていた次のような問題を含む指定した行で例外
Additional information: Unable to read data from the transport connection: Une connexion existante a dû être fermée par l’hôte distant.
してください任意のヘルプ私は数日から問題に直面していました。私はそれを理解できませんでした。 ありがとうございます
をブロック正確には、私がやったことです、実際にすべてのことをデバッグするときは大丈夫です。助けてください。ありがとう –
ファイアウォールをテストしましたか? – Coding4Fun
@aelbouchari私は127.0.0.1をIPアドレスとして入力しても何の例外もありませんので、ファイアウォールの問題だと思います。ありがとうございました。 –