Attached the TCP_Messaging module

Usage on system 1:

from TCP_Chat_04 import TCP_Messaging

myChat = TCP_Messaging()
myChat.Connect()

Usage on system 2:

from TCP_Chat_04 import TCP_Messaging

myChat = TCP_Messaging()
myChat.SendData('login_audio_Test message to display')

Note:
My message popup window has a method "DisplayMessage" to display the message. 
the string format should be (login_audiofile_Message)

let me know if any more details are required...


On Tuesday, December 11, 2012 12:11:10 PM UTC+5:30, Justin Israel wrote:
> Can you show some code surrounding the receiving of messages where you say it 
> hangs the app? 
> 
> 
> On Monday, December 10, 2012, PBLN RAO  wrote:
> 
> Actually i tiered sockets and developed the TCP_Messaging. its working but 
> when a message is received the application hangs. I made listening of 
> messaging to run in a thread and the data (message) is received it calls a 
> windows pops up at screen bottom right. As this all is happening in thread 
> the application hangs after receiving the 1st message.
> 
> 
> 
> 
> I read that twisted is a robust solution for this type of messaging.
> 
> 
> 
> Main agenda for developing this is for a two side communication between the 
> employees for are using this application installed.
> 
> 
> 
> For example:
> 
> 
> 
> I have a review system, where artists submits playblasts through this app and 
> details are saved in a database, supervisor will also use this app to review 
> the submitted files. so when he starts review, app will be sending messages 
> to the artist for a call to attend the review.
> 
> 
> 
> 
> Hope i made you clear about the main purpose of communication.
> 
> 
> 
> On Tuesday, December 11, 2012 12:22:12 AM UTC+5:30, Justin Israel wrote:
> 
> > Did you check out the docs and tutorials for twisted yet? Or are you asking 
> > if twisted is a good solution, or if something else can be recommended?
> 
> > What kind of communication will it be doing? 
> 
> >
> 
> >
> 
> >
> 
> >
> 
> >
> 
> > On Mon, Dec 10, 2012 at 5:12 AM, PBLN RAO <[email protected]> wrote:
> 
> >
> 
> > Hi,
> 
> >
> 
> >
> 
> >
> 
> > i have an application developed which works some parts internal to maya and 
> > some work as external to maya.
> 
> >
> 
> >
> 
> >
> 
> > We need to develop a communication between system [i.e., chatting or 
> > messaging what ever you say :)]
> 
> >
> 
> >
> 
> >
> 
> > I have a taught in mind of using twisted module for it. can anyone suggest 
> > where and how i should start....?
> 
> >
> 
> >
> 
> >
> 
> > the messaging should work in asynchronous mode so that my application will 
> > not hang when its in listen mode for receiving messages.
> 
> >
> 
> >
> 
> >
> 
> > --
> 
> >
> 
> > You received this message because you are subscribed to the Google Groups 
> > "Python Programming for Autodesk Maya" group.
> 
> >
> 
> > To post to this group, send email to [email protected].
> 
> >
> 
> > To unsubscribe from this group, send email to 
> > [email protected].
> 
> 
> 
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Python Programming for Autodesk Maya" group.
> 
> To post to this group, send email to [email protected].
> 
> To unsubscribe from this group, send email to 
> [email protected].

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].


# -*- coding: utf-8 -*-
"""
Created on Thu Nov 29 17:48:57 2012

@author: NARASIMHAPBL.1863
"""

# Echo server program
import os
import socket
import threading
import SocketServer
from Queue import Queue

from MessageWindow import messageWindow

global MsgPopUp
global MsgQ 

MsgPopUp = None
MsgQ = Queue()
    
class MessageHandler(SocketServer.StreamRequestHandler):
       
    def handle(self):
        
        global MsgPopUp
        global MsgQ
        
        msg = self.request.recv(1024)

        print MsgPopUp
        
        if MsgPopUp is None:
            MsgPopUp = messageWindow()
            print 'Msg window not exists'
            
        else:
            
            print 'Msg window exists'
            
        #my App hangs here on receiving the data
        #i think its due updating the message window within this thread
        MsgPopUp.DisplayMessage(msg)        
        print msg
        
class Listen(threading.Thread):
        
    def run(self):
        
        self.__Port = 50000
        self.server = SocketServer.TCPServer(('',self.__Port),MessageHandler)
        print 'configure server socket'
        self.server.serve_forever()
        
    def stop(self):
        
        self.server.shutdown()  
        
class TCP_Messaging():
    
    def __init__(self):
        
        self.__UserName = os.getenv('username')
        self.__Port = 50000
                
    def Connect(self):
        
        self.__Server = Listen()
        self.__Server.start()
        
    def Disconnect(self):
        
        self.__Server.stop()
        print 'Disconnected sucessfully'
        
    def SendData(self,txt,targetAddress):
        
        try:
            
            sendSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sendSocket.settimeout(0.01)
            sendSocket.connect((targetAddress, self.__Port))
            sendSocket.send(txt)
            
            
        except socket.gaierror:
            
            print 'Hostname could not be resolved.'
            
        except socket.error:
            
            print 'Messenger service is not running at target system.'
            
        finally:
            
            sendSocket.close()        

Reply via email to