[Zerofile-svn] SF.net SVN: zerofile: [56] trunk/src
Status: Pre-Alpha
Brought to you by:
karl-bengtsson
|
From: <kar...@us...> - 2007-11-27 13:04:42
|
Revision: 56
http://zerofile.svn.sourceforge.net/zerofile/?rev=56&view=rev
Author: karl-bengtsson
Date: 2007-11-27 05:04:34 -0800 (Tue, 27 Nov 2007)
Log Message:
-----------
Changed back to the old inheritance structure for chats/chat windows and simplified the chat session class greatly.
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/XMPPSessionListener.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-21 16:39:56 UTC (rev 55)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-27 13:04:34 UTC (rev 56)
@@ -6,10 +6,12 @@
*/
public class XMPPLinkLocalChatSession {
+ private boolean _sentHandshake = false;
+ private boolean _recievedHandshake =false;
private Socket _s;
private Reader _fromRemoteHost;
private PrintWriter _toRemoteHost;
- private PrintWriter _toUser = new PrintWriter(System.out,true);
+ //private PrintWriter _toUser = new PrintWriter(System.out,true);
private ZeroFileChatWindow _chatWindow;
private Thread _remoteHostReadingThread = new Thread() {
@@ -19,9 +21,10 @@
try {
while ((chars_read = _fromRemoteHost.read(buffer)) != -1)
{
- _toUser.write(buffer,0,chars_read);
- _toUser.flush();
- _chatWindow.printText(String.valueOf(buffer));
+ RecievedStanza(String.valueOf(buffer).substring(0,chars_read));
+ //_toUser.write(buffer,0,chars_read);
+ //_toUser.flush();
+ //_chatWindow.printText(String.valueOf(buffer));
}
}
catch (IOException e) {System.out.println(e);}
@@ -29,24 +32,31 @@
}
};
- public XMPPLinkLocalChatSession(ZeroFileChatWindow cW,XMPPLinkLocalHost hostToChatWith)
+ public void sendHandshake()
{
- _chatWindow = cW;
- connect(hostToChatWith.getHost(),hostToChatWith.getPort());
+ try
+ {
+ _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();
+ _sentHandshake = true;
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
}
- public XMPPLinkLocalChatSession(ZeroFileChatWindow cW,Socket s)
+ public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
{
- _chatWindow = cW;
+ _chatWindow = new ZeroFileChatWindow(this);
try
{
- _s = s;
+ _s = new Socket(hostToChatWith.getHost(),hostToChatWith.getPort());
+ _toRemoteHost = new PrintWriter(_s.getOutputStream());
_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();
+ sendHandshake();
}
catch (Exception e)
{
@@ -54,29 +64,39 @@
}
}
- public void sendMessage(String m)
+ private void RecievedStanza(String stanza)
{
- _toRemoteHost.print("<message><body>"+m+"</body></message>");
- _toRemoteHost.flush();
+ RecievedMessage(stanza);
}
- public void connect(String host,int port)
+ private void RecievedMessage(String mess)
{
+ if (_chatWindow == null)
+ _chatWindow = new ZeroFileChatWindow(this);
+ _chatWindow.printText(mess);
+ }
+
+ public XMPPLinkLocalChatSession(Socket s)
+ {
+ _s = s;
try
{
- _s = new Socket(host,port);
_fromRemoteHost = new InputStreamReader(_s.getInputStream());
+ _remoteHostReadingThread.start();
_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();
+ sendHandshake();
}
catch (Exception e)
{
System.out.println(e);
}
}
+
+ public void sendMessage(String m)
+ {
+ _toRemoteHost.print("<message><body>"+m+"</body></message>");
+ _toRemoteHost.flush();
+ }
public void disconnect()
{
Modified: trunk/src/XMPPSessionListener.java
===================================================================
--- trunk/src/XMPPSessionListener.java 2007-11-21 16:39:56 UTC (rev 55)
+++ trunk/src/XMPPSessionListener.java 2007-11-27 13:04:34 UTC (rev 56)
@@ -12,8 +12,8 @@
while(true)
{
Socket connection = _listeningSock.accept();
- new ZeroFileChatWindow(connection);
- //new XMPPLinkLocalChatSession(connection);
+ //new ZeroFileChatWindow(connection);
+ new XMPPLinkLocalChatSession(connection);
}
}
catch (Exception e)
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-21 16:39:56 UTC (rev 55)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-27 13:04:34 UTC (rev 56)
@@ -1,6 +1,5 @@
import java.awt.*;
import java.awt.event.*;
-import java.net.*;
import javax.swing.*;
@@ -14,7 +13,7 @@
private JTextField _entryTextField;
private JButton _sendButton;
private XMPPLinkLocalChatSession _session;
- public ZeroFileChatWindow(Socket sock)
+ /*public ZeroFileChatWindow(Socket sock)
{
this.ZeroFileChatWindowInit();
_session = new XMPPLinkLocalChatSession(this,sock);
@@ -25,6 +24,12 @@
hostToChatWith.updateData();
this.setWindowTitle(hostToChatWith.toString());
_session = new XMPPLinkLocalChatSession(this,hostToChatWith);
+ }*/
+
+ public ZeroFileChatWindow(XMPPLinkLocalChatSession sess)
+ {
+ this.ZeroFileChatWindowInit();
+ _session = sess;
}
public void setWindowTitle(String t)
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-21 16:39:56 UTC (rev 55)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-27 13:04:34 UTC (rev 56)
@@ -29,8 +29,8 @@
static void addHost(XMPPLinkLocalHost h)
{
- System.out.println("forsoker adda: " + h.toString());
- //h.updateData();
+ //System.out.println("forsoker adda: " + h.toString());
+ h.updateData();
_contactListModel.addElement(h);
}
@@ -122,8 +122,8 @@
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
- new ZeroFileChatWindow((XMPPLinkLocalHost)_contactList.getSelectedValue());
- //new XMPPLinkLocalChatSession((XMPPLinkLocalHost)_contactList.getSelectedValue());
+ //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.
|