Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

A networks in java question

Options
  • 17-03-2004 4:47pm
    #1
    Registered Users Posts: 658 ✭✭✭


    I have two computers connected via a lan connection. On each computer i have a javaswing GUI. The problem is as follows.......


    On computer 'A's GUI I enter a string into a textfield and press the submit.

    What I want to do is...

    Take the string from the textfield on computer 'A' and display it in a textfield in the GUI on computer 'B'.

    Am i right in saying the code would look something like this??....

    public static String message;
    message = TextfieldA.getText();
    // how do i then send it to the textfield on computers B's GUI???????

    is it?...

    TextFieldB.setText(what goes in here?);


Comments

  • Registered Users Posts: 678 ✭✭✭briano


    Are the two computers "talking" to each other over the network connection? That would be the first step. After that, the method of displaying the message in B's Textfield depends on how you chose to send messages across to that computer.


  • Registered Users Posts: 3,958 ✭✭✭Chad ghostal


    just like he said youll to use some networking,
    like rmi or sockets or something..
    rmi would probably be the easiest thing to use..
    there are loads of tutorials on the web for this kind of thing..


  • Registered Users Posts: 658 ✭✭✭Chunks


    yeah, they are constantly "talking" to each other over the connection. The problem is I dont know how to send info across the connection and how to retrieve it on the other end. Im not any good with networks. Lehmans terms is the only thing i understand when it comes to this kind of thing. Any more help? Like if you were to write code to do it what would it look like?

    Cheers


  • Registered Users Posts: 678 ✭✭✭briano


    Sorry, I should have been more clear about the computers talking to each other. What I meant to say was "are the two java applications communicating with each other?" I'll take it that they are not.

    If you are handy with interfaces and don't mind some messing around then use java RMI. The tutorial is here . Read through it and it should make it clear enough.

    If you just want to send text, in a fairly predictable manner (say, always from program A to program B), between the two applications then you could use Sockets. The tutorial for sockets is here


  • Registered Users Posts: 1,350 ✭✭✭skywalker_208


    Sockets is definately the way to go for something this simple.... If u have access to a library get the Dietal & Dietal Java How To Program third or fourth edition.... that has a pretty good chapter on this kind of stuff....


  • Advertisement
  • Registered Users Posts: 658 ✭✭✭Chunks


    Ah nice one guys, I really appreciate the help.

    Thanks a lot, very helpful


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Sounds like you are doing a chat program.

    Afaik, there are 3 main ways to run chat services:
    Direct Client Connection: You have one program. It incorporates a GUI, a client socket set, and a server socket set. Basically, given an IP address of another machine, it connects to the other client and start chatting. This is the basis of things like winchat.

    Server Relay: You have two programs, One is a (usually) GUI-less server, the other a client with no server, just a GUI on top of client sockets. The clients connect to the server, which then relays any messages to any clients who are listening. This is the basis of IRC.

    Server negotiated Direct Client Connection (May not be the correct name for it): An amalgamation of the two. Clients connect to the server. When a client wishes to connect to another one, it gets the relevant information from the server (ip address, ports, some authentication info where necessary), and then initiates a DCC. Afaik, this could be the basis on which things like MSN Messenger work, but I could be very wrong.

    This page might be of use to you: http://www.javaworld.com/javaworld/jw-01-1997/jw-01-chat.html

    There could be pages of threads discussing the relative benefits/shortcomings of each, as well as ways to do it, but which way you do it depends on how much effort you want to put in, and of course your requirements (assuming it's for college).

    If it's not a chat program you're doing, I've just wasted 15 minutes of my life :D


  • Registered Users Posts: 491 ✭✭Silent Bob


    Originally posted by seamus
    Sounds like you are doing a chat program.
    I could imagine Clippy showing up in Visual Studio to say this :)


Advertisement