Pastes:104609  Views:2165101 

Languages:

   ASP
   C#
   C++
   HTML
   Java
   PHP
   VB.NET
   Visual Basic 6

more languages available...


Looking to freelance?


Warning: file_get_contents(http://www.getafreelancer.com/affiliates/itsdan/6f.txt) [function.file-get-contents]: failed to open stream: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? in /home/nmp/public_html/support/googlereferrals.php on line 21
( bids)

Source: GetAFreelancer.com


3D Engine and Development SDK

 

 

 

 

 

 

Here's the requested code from the pastebin:

Wrap Lines   Use Line Numbers
Alan, here's what happened:
 
C:\JYTHON~1.2RC>jython minirc.py
*sys-package-mgr*: processing new jar, 'C:\jython2.2rc1\jython.jar'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre1.5.0_10\lib\ext\QTJava.zip'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre1.6.0_01\lib\resources.jar'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre1.6.0_01\lib\rt.jar'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre1.6.0_01\lib\jsse.jar'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre1.6.0_01\lib\jce.jar'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre1.6.0_01\lib\ext\dnsns.jar'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre1.6.0_01\lib\ext\sunjce_provider.jar'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre1.6.0_01\lib\ext\sunmscapi.jar'
*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre1.6.0_01\lib\ext\sunpkcs11.jar'
Traceback (innermost last):
  File "minirc.py", line 133, in ?
  File "minirc.py", line 130, in main
  File "minirc.py", line 26, in newSession
  File "minirc.py", line 59, in connect
  File "minirc.py", line 71, in sockread
  File "minirc.py", line 112, in checkstatus
  File "C:\jython2.2rc1\Lib\socket.py", line 523, in send
  File "C:\jython2.2rc1\Lib\socket.py", line 109, in write
        at sun.nio.ch.SocketDispatcher.write0(Native Method)
        at sun.nio.ch.SocketDispatcher.write(Unknown Source)
        at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source)
        at sun.nio.ch.IOUtil.write(Unknown Source)
        at sun.nio.ch.SocketChannelImpl.write(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
 
java.io.IOException: java.io.IOException: An established connection was aborted
by the software in your host machine
 
######################################
#
# Here's the exact code I'm using (It connects to Los Angeles undernet server)
#
#
from java.awt import *
from java.awt.event import ActionListener
from javax.swing import UIManager, JFrame, JScrollPane, JTextField, JTextArea
 
import socket
 
try:
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
except:
    pass
 
class IRCclient(JFrame):
 
    def __init__(self):
        JFrame.__init__(self, "MiniClient", defaultCloseOperation=3, size=(500, 400))
        f = ('monospaced', Font.PLAIN, 13)
        self.textarea = JTextArea('', font=f, editable=0, lineWrap=1, wrapStyleWord=1)
        self.editbox = JTextField('', font=f)
        self.getContentPane().add(JScrollPane(self.textarea), BorderLayout.CENTER)
        self.getContentPane().add(self.editbox, BorderLayout.SOUTH)
        self.show()
        self.editbox.requestFocus()
 
    def newSession(self):
        s = IRCsession(self)
        s.connect()
 
 
class AActionListener(ActionListener):
    """
    I know this could have been written better,
    but I started writing this when I was a newbie to Jython.
    """
    def __init__(self, args):
        self.docommand = args
 
    def actionPerformed(self, event):
        self.docommand(event.getSource() , event.getSource().getText())
 
class IRCsession:
 
    def __init__(self, client):
        self.sockname = None
        self.client = client
        self.client.editbox.addActionListener(AActionListener(self.inputparser))
 
    def connect(self):
        self.echo("Attempting to connect")
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect(('LosAngeles.CA.US.undernet.org', 6667))
            self.sockname = s
            self.sockwrite('USER %s %s %s :%s' % ('ident', 'server', 'ident', 'realname'))
            self.sockwrite('NICK mynick')
        except socket.error:
            self.sockname = None
            self.echo("Socket error in connect()")
        if self.sockname is not None:
            self.sockread()
 
    def sockread(self):
        sockname = self.sockname
        readbuffer = ''
        while 1:
            try:
                readbuffer = readbuffer + sockname.recv(1024)
                data = readbuffer.split("\n")
                readbuffer = data.pop()
                if len(data) > 0:
                    self.sockparse(data)
                elif self.checkstatus() == 'ERR':
                    """
                     If len(data) is 0, I don't want to assume that I've been
                     disconnected. Hence, I do a checkstatus() which is a try/except.
                     If the exception occurs, only then I should be able to safely
                     conclude that I'm offline.
                    """
                    self.echo("Seems to be disconnected")
                    break
            except socket.error:
                self.sockname = None
                self.echo("Socket error in sockread()")
                break
 
    def echo(self, data):
        target = self.client.textarea
        target.append(data + '\n')
        target.setCaretPosition(target.getDocument().getLength())
 
    def sockparse(self, data):
            for line in data:
                line = line.rstrip()
                line_split = line.split(' ')
                if line_split[0] == 'PING':
                    self.sockwrite('PONG ' + line_split[1])
                self.echo(line)
 
    def sockwrite(self, data):
        self.echo('Sending data: ' + data)
        if self.sockname is not None:
            self.sockname.send(data + '\r\n')
 
 
    def checkstatus(self):
        """
           I still use self.sockname because during sockread,
           the self.sockname value is only set to None only if there is
           a socket exception. So by right, sockname SHOULD still have
           some value at this point.
        """ 
        try:
            self.sockname.sendall('PING\n')
            return 'OK'
        except socket.error, sockerr:
            """
               sockerr is there because I want to print it out, do stuff, etc.
            """
            self.sockname.close()
            return 'ERR'
 
    def inputparser(self, editbox, data):
        if data[0] == '/':
            parms = data.split(' ')
            parm1 = parms[0][1:].upper() + ' '
            self.sockwrite(parm1 + ' '.join(parms[1:]))
            editbox.setText('')
 
def main():
    c = IRCclient()
    c.newSession()
 
if __name__ == '__main__':
    main()
Syntax Highlighting:  



Copyright 2007 - NoMorePasting.com