package rpicq; import java.net.*; import java.io.*; /** * This is a bare bones interface to a Connection used to talk on RPIcq. * This connection would be theoretically used to chat between two clients * directly, not through the server. It can be modified as you see fit to * connect to your server. * * The client performs two basic functions: * * It reads messages from the person you are talking to, and posts * them to mFrame by calling mFrame.addRemoteMessage(String) * * It sends messages entered by the local user to the user at the * other end of the wire. It does this by sending everything it * gets in the getMessage() Method from the MessageListener Interface. **/ public class ConnectionSkeleton extends Thread implements MessageListener { private String mServerName; private int mPort; private MessageSplitFrame mFrame; private Socket mSyncSocket; // you may or may not want another socket, as well // as input and output streams here /** * This constructor is used to connect this user in conversation to * another user. The conversation will appear in the frame inFrame **/ public ConnectionSkeleton(String inServerName, int inPort, MessageSplitFrame inFrame) { mServerName = inServerName; mPort = inPort; mFrame = inFrame; // necessary code mFrame.addMessageListener( this ); // connect the Socket to the Server // maybe start the thread by calling .start() } /** * You may want to create another constructor, since there will be times * when another user in trying to start a conversation with you, not having * you initiate the transaction. public ConnectionSkeleton() { } /** * This method is used to specify which frame is recieving this * connection's conversation, if it hasn't already been specified in the * constructor. **/ public void setMessageFrame( MessageSplitFrame msf ) { mFrame = msf; } /** * The Connection should run and recieve messages here. **/ public void run() { // get a message off the wire. // call mFrame.addRemoteMessage( text ); } /** * This method is called by the frame that this connection is related to. * Everytime the local user types something, it will be sent here. * From here, you need to get the message out of the MessageEvent, and * send it to the conversation partener, in any way you see fit.*/ public void gotMessage(MessageEvent inEvent) { } }