Sending text - C# DLL to Java Server

Started by
3 comments, last by AcePilot 17 years, 11 months ago
Hello everyone, Let me tell you about my program. I have a C++ Client, that connects to a C# DLL. The C# Dll communicate with a distant Java Server ( for the moment and testing purpose It's local ) My C# DLL communicate with my Java Server through a Socket. First of all, my C++ Client communicate #1 with my C# DLL. Also my C# DLL is able to connect with my Java Server throught the socket. the problem is, I send in my C# DLL an array of bytes to my Java Server. But the DataInputStream in my Java server seems to not be able to retrieve what I'v sent. What's wrong This is my C# DLL in one of my function (btw sorry but some names are french :( But in that case i believe they aren't important )

Socket ServeurSocket = null;
		public int GetNombreAvions()
		{
			IPHostEntry lipa = Dns.Resolve("localhost");
			IPEndPoint lep = new IPEndPoint(lipa.AddressList[0], 5555);

			ServeurSocket = new Socket(lep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
			byte[] msg = Encoding.ASCII.GetBytes("CMD.NOMBRE");

			ServeurSocket.Connect(lep);

			if(ServeurSocket.Connected)
			{
				ServeurSocket.Send(msg, msg.Length, SocketFlags.None);

				//Wait Return Message
				byte[] MsgReturn = new byte[1024];
				ServeurSocket.Receive(MsgReturn,0, ServeurSocket.Available, SocketFlags.None);
	
				return int.Parse(Encoding.ASCII.GetString(MsgReturn));
			}
			return -1;
		}

And Heres My Java Server objet and where i retrieve the data sent.

		Socket socket;
		ServerSocket socketServeur;
		
		DataInputStream reader;
		PrintWriter writer;

writer = new PrintWriter(
						new OutputStreamWriter(
							socket.getOutputStream() ), true );
							
			reader = new DataInputStream(socket.getInputStream());
			
			System.out.println( "Client connecte" );
			System.out.println(reader.readLine());

If you need any additional source code, tell me so and I'll put it. Thank for your help.
Advertisement
have you tried putting any of these blocks of code in a catch? You may be getting some exceptions you don't know about.
We'll bring your children up in the classic English manner, by making them learn latin, and beating them half to death in a single sex environment.
These instruction are all in a Try Catch statement, and I get nothing on that side sadly.
if(ServeurSocket.Connected)			{				ServeurSocket.Send(msg, msg.Length, SocketFlags.None);				//Wait Return Message				byte[] MsgReturn = new byte[1024];				ServeurSocket.Receive(MsgReturn,0, ServeurSocket.Available, SocketFlags.None);


I have never coded in C# so I am unfamiliar how the socket services work... Is it possible the ServeurSocket.Send method is buffered? Is there a ServeurSocket.Flush method?

On the java side of things...

System.out.println(reader.readLine());


DataInputStream.readLine has been depriciated for a very long time. Also make sure the input method you use is blocking, or you do a check for data, loop scheme.

I assume you have removed some of the Java source in this post (initialization etc...)
∫Mc
Try replacing the Java server with a C# server. If the problem persists, then I don't think there is anything wrong with the program. If it doesn't, then you will have to debug your Java server code.

This topic is closed to new replies.

Advertisement