0

I am doing communication with Java server. One application which is developed in java and it runs on some ip,port. e.g. 192.168.1.1 port 9090 No wi want to communicate to that server using my ASp .NET ( C# )

I have following scenario:

  1. connection with server
  2. once the data has been trasferred, i have to inform the server that my data transfer is complete. So after that the server will process the data and will revert me(respone).
  3. Then i will have to read that data.

When i am using the NetworkStream class.

I have 1 method which i am using is write to send data.

But the server dont understand the complete data has been received or not. So it continuously wait for the data.

So how to do this?

1
  • 1
    It's not really possible to help you if you don't give us some code to see how you have built your client and server. Commented Feb 29, 2012 at 12:54

1 Answer 1

1

Maybe you could consider to use Eneter Messaging Framework for that communication.
It is the lightweight cross-platform framework for the interprocess communication.

The Java service code would look something like this:

// Declare your type of request message.
public static class MyRequestMsg
{
    public double Number1;
    public double Number2;
}

// Declare your type of response message.
public static class MyResponseMsg
{
    public double Result;
}


public static void main(String[] args) throws Exception
{
    // Create receiver that receives MyRequestMsg and
    // responses MyResponseMsg
    IDuplexTypedMessagesFactory aReceiverFactory = new DuplexTypedMessagesFactory();
    myReceiver = 
      aReceiverFactory.createDuplexTypedMessageReceiver(MyResponseMsg.class, MyRequestMsg.class);
    
    // Subscribe to handle incoming messages.
    myReceiver.messageReceived().subscribe(myOnMessageReceived);
    
    // Create input channel listening to TCP.
    IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
    IDuplexInputChannel anInputChannel = 
      aMessaging.createDuplexInputChannel("tcp://127.0.0.1:4502/");

    // Attach the input channel to the receiver and start the listening.
    myReceiver.attachDuplexInputChannel(anInputChannel);
    
    System.out.println("Java service is running. Press ENTER to stop.");
    new BufferedReader(new InputStreamReader(System.in)).readLine();
    
    // Detach the duplex input channel and stop the listening.
    // Note: it releases the thread listening to messages.
    myReceiver.detachDuplexInputChannel();
}

private static void onMessageReceived(Object sender, 
             TypedRequestReceivedEventArgs<MyRequestMsg> e)
{
    // Get the request message.
    MyRequest aRequest = e.getRequestMessage();
    
    ... process the request ...
            
    // Response back the result.
    MyResponseMsg aResponseMsg = new MyResponseMsg();
    ... set the result in the response message ...
    
    try
    {
        // Send the response message.
        myReceiver.sendResponseMessage(e.getResponseReceiverId(), aResponseMsg);
    }
    catch (Exception err)
    {
        EneterTrace.error("Sending the response message failed.", err);
    }
}


// Handler used to subscribe for incoming messages.
private static EventHandler<TypedRequestReceivedEventArgs<MyRequestMsg>> myOnMessageReceived
        = new EventHandler<TypedRequestReceivedEventArgs<MyRequestMsg>>()
{
    @Override
    public void onEvent(Object sender, TypedRequestReceivedEventArgs<MyRequestMsg> e)
    {
        onMessageReceived(sender, e);
    }
};

And the .NET client would look something like this:
            public class MyRequestMsg
    {
        public double Number1 { get; set; }
        public double Number2  { get; set; }
    }
    
    public class MyResponseMsg
    {
        public double Result { get; set; }
    }


    private IDuplexTypedMessageSender<MyResponseMsg, MyRequestMsg> myMessageSender;
    

    private void OpenConnection()
    {
        // Create message sender.
        // It sends string and as a response receives also string.
        IDuplexTypedMessagesFactory aTypedMessagesFactory = new DuplexTypedMessagesFactory();
        myMessageSender =
           aTypedMessagesFactory.CreateDuplexTypedMessageSender<MyResponseMsg, MyRequestMsg>();

        // Subscribe to receive response messages.
        myMessageSender.ResponseReceived += OnResponseReceived;

        // Create TCP messaging.
        IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
        IDuplexOutputChannel anOutputChannel =
           aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:4502/");

        // Attach the output channel to the message sender and be able
        // send messages and receive responses.
        myMessageSender.AttachDuplexOutputChannel(anOutputChannel);
    }

    private void CloseConnection(object sender, FormClosedEventArgs e)
    {
        // Detach output channel and stop listening to response messages.
        myMessageSender.DetachDuplexOutputChannel();
    }

    private void SendMessage()
    {
        // Create message.
        MyRequestMsg aRequestMessage = new MyRequestMsg();
        ...
        
        // Send message.
        myMessageSender.SendRequestMessage(aRequestMessage);
    }

    private void OnResponseReceived(object sender,
                              TypedResponseReceivedEventArgs<MyResponseMsg> e)
    {
        // Get the response message.
        MyResponseMsg aResponse = e.ResponseMessage;
        
        .... process the response from your Java client ....
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.