This is how my code looks like:
import socket
import select

class ChatServer:

    def __init__( self):
        self.port = 8880;
        self.srvsock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
        self.srvsock.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 )
        self.srvsock.bind( ("", 8880) )
        self.srvsock.listen( 5 )
        print("New socket bind")
        while 1:
            print("Waiting for new connection")
            self.sock,(remhost,remport)=self.accept_new_connection()
        print ('ChatServer started on port %s' % port)

    def send(self,data):
        self.sock.send(data)
    def receieve(self):
        self.str=sock.recv(1024)
        print(self.str)


I want to run this code first time when my project starts and want to call 
send() and receive() functions from other two different python files 
located in different path.
  

On Saturday, 21 October 2017 16:33:27 UTC+5:30, Justin Israel wrote:
>
>
>
> On Sat, Oct 21, 2017, 11:06 PM T Obulesu <[email protected] <javascript:>> 
> wrote:
>
>> Hi All,
>>
>> I'm new to python3 and scratching my head to write a program for this 
>> logic:
>>
>> classA.py
>> Class A:
>>           # class for socket communication
>>           basic init method that initializes port, address, connection
>>
>>          method send(message):
>>          # for sending any message through the given port
>>
>>
>>        method receive():
>>        # will be keep on listening for incoming messages
>>
>>
>>
>> classB.py
>>
>> Class B:
>>            import the send method from class A
>>            send the messages from this class
>>
>>
>> classC.py
>>
>> Class C:
>>             import the receive method from the class A
>>             receive all the messages from the same socket from here.
>>
>>
>>
>> Note: 
>>  classA.py, classB.py, ClassC.py are saved in different locations.
>>
>>
>> Can someone help me in writing the code and how can I create a single 
>> object and use it in multiple classed?
>>
>
>
> It might help if you explain a little more concretely about what problem 
> you are actually trying to solve. Are you trying to create a generic socket 
> connection class that knows how to send and receive, and then use send 
> functionality in one subclass, and receive functionality in another? 
>
> What code have you written thus far and where are you stuck? At this stage 
> it seems a bit code-golfy to try and just write your specification for you. 
>
> Are you new to python 3 and looking for a newer way to solve this problem 
> as opposed to how you would have done it via python 2? Also... Is this 
> homework? 
>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/python_inside_maya/d457de3d-4353-47b4-906c-187d616cd9fe%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/python_inside_maya/d457de3d-4353-47b4-906c-187d616cd9fe%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/be550507-7ccd-4a99-bd56-cebfda87f24f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to