1 2 Previous Next 29 Replies Latest reply on Jun 17, 2008 1:01 AM by 807591

    [HELP] Connect JAVA server to C# server

    807591
      Good afternoon,
      as i am new here, i don't know if i'm posting on the right place.

      I have a C# server listening on port (for instance 6666) at the address of http://ssh:6666 .
      I want my existing JAVA server to connect to it, and send / receive information.

      How do i connect to it? And open some Input and Output streams...

      Thank you
        • 1. Re: [HELP] Connect JAVA server to C# server
          807591
          [The Java� Tutorial - Lesson: All About Sockets|http://java.sun.com/docs/books/tutorial/networking/sockets/]

          ~
          • 2. Re: [HELP] Connect JAVA server to C# server
            796440
            It doesn't matter what language the server was written in and it doesn't matter what language you're writing the client in. The approach is the same: Open a socket to the appropriate IP address and port, send bytes using the protocol that that server expects, and process the reply bytes as appropriate to that protocol.

            Start here: [http://java.sun.com/docs/books/tutorial/networking/sockets/index.html]

            and then google for "java ssh".
            • 3. Re: [HELP] Connect JAVA server to C# server
              807591
              Thanks, i can now connect to my C# server (because he writes on the command line that a new connection was opened)

              Just one problem now....he can't read what i send to him!!

              And i have a read_line method in my C# that reads everything in the socket... please take a look at my code!
              Socket echoSocket = null;
                      PrintWriter out = null;
                      BufferedReader in = null;
              
                      try {
                          echoSocket = new Socket("ssh.dei.isep.ipp.pt", 6666);
                          out = new PrintWriter(echoSocket.getOutputStream(), true);
                          in = new BufferedReader(new InputStreamReader(
                                                      echoSocket.getInputStream()));
                      } catch (UnknownHostException e) {
                          System.err.println("Don't know about host: SSH.");
                          System.exit(1);
                      } catch (IOException e) {
                          System.err.println("Couldn't get I/O for "
                                             + "the connection to: SSH.");
                          System.exit(1);
                      }
              
                   BufferedReader stdIn = new BufferedReader(
                                                 new InputStreamReader(System.in));
                   String userInput;
                      System.out.println("Vou tentar enviar Testing");
                      out.print("Testing Testing");
                      System.out.println("Terminei o envio");
                   while ((userInput = stdIn.readLine()) != null) {
                       out.println(userInput);
                       System.out.println("echo: " + in.readLine());
                   }
              
                   out.close();
                   in.close();
                   stdIn.close();
                   echoSocket.close();
              • 4. Re: [HELP] Connect JAVA server to C# server
                807591
                Just one problem now....he can't read what i send to him!!
                Time to start troubleshooting, then.

                ~
                • 5. Re: [HELP] Connect JAVA server to C# server
                  807591
                  Not really seeing a lot of encyrption in the above code...
                  • 6. Re: [HELP] Connect JAVA server to C# server
                    807591
                    mindfields wrote:
                    Thanks, i can now connect to my C# server (because he writes on the command line that a new connection was opened)

                    Just one problem now....he can't read what i send to him!!
                    Can you prove that the C# side of things works? How?
                    • 7. Re: [HELP] Connect JAVA server to C# server
                      796440
                      Forget about ssh for now. Just create a simple echo server and connect to it from your client. When you get that working, start digging into how ssh works, and google for a Java ssh library.
                      • 8. Re: [HELP] Connect JAVA server to C# server
                        807591
                        the C# server that i'm using is an HTTP server. He reads and prints everything in the socket....

                        I opened a page now in http://ssh:6666 and he sent the header and body perfectly :\
                        • 9. Re: [HELP] Connect JAVA server to C# server
                          807591
                          edit: talking rubbish there, sorry

                          Edited by: georgemc on Jun 16, 2008 5:09 PM
                          • 10. Re: [HELP] Connect JAVA server to C# server
                            807591
                            mindfields wrote:
                            the C# server that i'm using is an HTTP server.
                            There are multiple problems with what you are sending.

                            1) No encyrption

                            2) Not HTTP

                            Thankfully you can stop all this and just use a HttpsURLConnection. What you need to do is use a URL but tell it what port and protocol to speak (since your URL and port are odd that way).
                            • 11. Re: [HELP] Connect JAVA server to C# server
                              796440
                              mindfields wrote:
                              the C# server that i'm using is an HTTP server. He reads and prints everything in the socket....

                              I opened a page now in http://ssh:6666 and he sent the header and body perfectly :\
                              What are you trying to accomplish here?

                              Are you just trying to learn the basics of sockets? If so, forget this server and just use the tutorial and write your own non-encrypted, non-HTTP client/sever pair.

                              Are you trying to write a real Java program that will interact with this server? If so, then follow cotton's advice in reply 10, though it would still serve you to get a solid grounding in sockets, HTTP, and whatever protocol that server is using. The name "ssh" is confusing, given that there's clearly no encryption happening.
                              • 12. Re: [HELP] Connect JAVA server to C# server
                                807591
                                jverd wrote:

                                What are you trying to accomplish here?

                                Are you just trying to learn the basics of sockets? If so, forget this server and just use the tutorial and write your own non-encrypted, non-HTTP client/sever pair.

                                Are you trying to write a real Java program that will interact with this server? If so, then follow cotton's advice in reply 10, though it would still serve you to get a solid grounding in sockets, HTTP, and whatever protocol that server is using. The name "ssh" is confusing, given that there's clearly no encryption happening.
                                Hi jverd... I have a JAVA HTTP server, in which i receive some variables from the browser (this is working) . Then i have to send some text with those variables to a C# server. This C server is running on the ssh of my university, the ssh.dei.isep.ipp.pt and is running in comand line (like putty or telnet... )

                                I want to create a connection with it (on any port) and send those texts to it.

                                Is it possible?
                                Hope you understand my english,
                                Thanks for your time .
                                • 13. Re: [HELP] Connect JAVA server to C# server
                                  807591
                                  mindfields wrote:
                                  jverd wrote:

                                  What are you trying to accomplish here?

                                  Are you just trying to learn the basics of sockets? If so, forget this server and just use the tutorial and write your own non-encrypted, non-HTTP client/sever pair.

                                  Are you trying to write a real Java program that will interact with this server? If so, then follow cotton's advice in reply 10, though it would still serve you to get a solid grounding in sockets, HTTP, and whatever protocol that server is using. The name "ssh" is confusing, given that there's clearly no encryption happening.
                                  Hi jverd... I have a JAVA HTTP server, in which i receive some variables from the browser (this is working) . Then i have to send some text with those variables to a C# server. This C server is running on the ssh of my university, the ssh.dei.isep.ipp.pt and is running in comand line (like putty or telnet... )

                                  I want to create a connection with it (on any port) and send those texts to it.

                                  Is it possible?
                                  Hope you understand my english,
                                  Thanks for your time .
                                  I really don't think you're capable of doing this.

                                  You have been plenty of good advice here. From me and others.

                                  And neverminding the English your posts are simply contradicting themselves. In one post you said the Java Server is HTTP and in another you said the C# is HTTP. Are both HTTP?

                                  What exactly IS the C# server?

                                  Do you understand yet that your posted code does not use ANY encyrption at all?
                                  • 14. Re: [HELP] Connect JAVA server to C# server
                                    807591
                                    Yes, both are HTTP server! One in Java and other in C...
                                    The server in java receives some variables from the browser and then he has to work like a client, and forward those variables to a C Server.

                                    It's a very complex situation i guess
                                    1 2 Previous Next