0
I was trying to create a socket 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 code C#: http://pastebin.com/m2Vpznts
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: http://pastebin.com/2ewZtxVk
I have an example of code that only uses Sockets. Does it fit you? Can I put this in the answer?
– carlosrafaelgn
Well, I would like to send a message socket 'Hello' from the java client (Android), to a C server. If you have any relation would be a favor.
– user2568864
I think the answer below has already worked! : ) Still want the example only with
Socket
server side, withoutTcpListener
?– carlosrafaelgn