Sign in to follow this  
deathwearer

Sending text - C# DLL to Java Server

Recommended Posts

deathwearer    367
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.

Share this post


Link to post
Share on other sites
smc    292
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...)

Share this post


Link to post
Share on other sites
AcePilot    252
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this