I was trying to create a sockets connection between Java and C #, Java being the client and C # the server.
But when I use BinaryReader to read the data, it returns an error:
Unable to read beyond the end of the stream.
Excerpt from the C # code that reads:
Console.WriteLine("Iniciando...");
IPEndPoint ipp = new IPEndPoint(IPAddress.Parse("192.168.173.1"), 5000);
tccp=new TcpListener(ipp);
tccp.Start();
Console.WriteLine("Conexão TCP iniciada, ip : 127.0.0.1, porta: 4567");
doidaco = tccp.AcceptSocket();
newton = new NetworkStream(doidaco);
rr = new BinaryReader(newton);
string mensagem="";
do{
mensagem = rr.ReadString();
Console.WriteLine("\nMensagem do cliente: "+mensagem);
}while(doidaco.Connected);
Complete C # code: link
The Java code that is sending the message through the socket is as follows:
public static void main(String[] args) throws IOException {
socket = new Socket("192.168.173.1", 5000);
Scanner sca = new Scanner(socket.getInputStream());
PrintWriter ee = new PrintWriter(socket.getOutputStream());
ee.println("Hello!");
System.out.println("Mensagem enviada.");
ee.close();
System.out.println("Conexão encerrada.");
sca.close();
socket.close();
}
Java code: link