Can we run both Socket Server and Socket Client on the same Django Server?

197 Views Asked by At

I have a Django Server work as 2 role: Socket Server and Socket Client.

1/ As a Socket Server, it work on local side, so some clients in same network can connect and receive event.

2/ As a Socket Client, it will connect (using Socket) to another Remote Server to receive events and forward that events to all local clients

But when Socket Client receive events then emit to local clients by Socket Server, nothing happen (local clients can't receive that events).

It seem Socket Server and Client can't working together. Here is some sample of my code:

// Receive event from Remote Server
self.__client__.on("event_msg", self.onEvent)

// Forward event to local Clients
def onEvent(self, package):
    self.__socketServer__.emitEvent(event="event_msg", data=package, to=None, room="123")

The __socketServer__ is just an instance of SocketServer class, and it can work if just simple send/receive message in local network (not put in socket client event)

I'm using python-socketio for both Server+Client

0

There are 0 best solutions below