[Zerofile-svn] SF.net SVN: zerofile: [48] trunk/src
Status: Pre-Alpha
Brought to you by:
karl-bengtsson
|
From: <kar...@us...> - 2007-11-13 13:55:21
|
Revision: 48
http://zerofile.svn.sourceforge.net/zerofile/?rev=48&view=rev
Author: karl-bengtsson
Date: 2007-11-13 05:55:03 -0800 (Tue, 13 Nov 2007)
Log Message:
-----------
We can now send messages, and read them out to the console. Parsing is required, as is fault tolerance, etc etc. Yay!
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-10 12:51:28 UTC (rev 47)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-13 13:55:03 UTC (rev 48)
@@ -1,3 +1,6 @@
+import java.io.*;
+import java.net.*;
+
/*
* Class for handling chat sessions.
*/
@@ -4,22 +7,64 @@
public class XMPPLinkLocalChatSession {
private XMPPLinkLocalHost _remoteHost;
+ private Socket _s;
+ private Reader _fromRemoteHost;
+ private PrintWriter _toRemoteHost;
+ private PrintWriter _toUser = new PrintWriter(System.out,true);
+ private ZeroFileChatWindow _chatWindow;
+ private Thread _remoteHostReadingThread = new Thread() {
+ public void run() {
+ char[] buffer = new char[1024];
+ int chars_read;
+ try {
+ while ((chars_read = _fromRemoteHost.read(buffer)) != -1)
+ {
+ _toUser.write(buffer,0,chars_read);
+ _toUser.flush();
+ }
+ }
+ catch (IOException e) {System.out.println(e);}
+ System.out.println("Connection closed!");
+ }
+ };
public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
{
_remoteHost = hostToChatWith;
connect();
+ _chatWindow = new ZeroFileChatWindow(this);
}
public void sendMessage(String m)
{
- int port = _remoteHost.getPort();
+ _toRemoteHost.print("<message><body>"+m+"</body></message>");
+ _toRemoteHost.flush();
+ //System.out.println(m);
+ /*int port = _remoteHost.getPort();
String hostName = _remoteHost.getHost();
System.out.println("The text \"" + m + "\" should now be sent to:");
- System.out.println(hostName + ":" + port);
+ System.out.println(hostName + ":" + port);*/
}
public void connect()
{
- // TODO - establish connection to host
+ try
+ {
+ _s = new Socket(_remoteHost.getHost(),_remoteHost.getPort());
+ _fromRemoteHost = new InputStreamReader(_s.getInputStream());
+ _toRemoteHost = new PrintWriter(_s.getOutputStream());
+ _remoteHostReadingThread.start();
+ _toRemoteHost.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
+ _toRemoteHost.print("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>");
+ _toRemoteHost.flush();
+ //_toRemoteHost.print(s);
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
}
+ public XMPPLinkLocalHost getRemoteHost()
+ {
+ return _remoteHost;
+ }
public void disconnect()
{
// TODO - disconnect from host
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-10 12:51:28 UTC (rev 47)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-13 13:55:03 UTC (rev 48)
@@ -14,12 +14,12 @@
private JTextField _entryTextField;
private JButton _sendButton;
private XMPPLinkLocalChatSession _session;
- public ZeroFileChatWindow(XMPPLinkLocalHost chatPartner)
+ public ZeroFileChatWindow(XMPPLinkLocalChatSession chatSession)
{
- chatPartner.updateData();
- _session = new XMPPLinkLocalChatSession(chatPartner);
+ _session = chatSession;
+ _session.getRemoteHost().updateData();
_chatWindowFrame = new JFrame();
- _chatWindowFrame.setTitle(chatPartner.toString());
+ _chatWindowFrame.setTitle(_session.getRemoteHost().toString());
_chatWindowFrame.setLayout(new GridLayout(0,1,1,1));
_chatWindowFrame.setLocation(0,400);
_chatWindowFrame.setSize(new Dimension(300,200));
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-10 12:51:28 UTC (rev 47)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-13 13:55:03 UTC (rev 48)
@@ -109,7 +109,7 @@
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
- new ZeroFileChatWindow((XMPPLinkLocalHost)_contactList.getSelectedValue());
+ new XMPPLinkLocalChatSession((XMPPLinkLocalHost)_contactList.getSelectedValue());
}
});
_mainWindowFrame.add(_contactList);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|