문제

My clients speak with my servers over custom protocol. Now I'm adding chat system backed by XMPP server (ejabberd). My server will tunnel user messages to XMPP server by logging in XMPP server on behalf of all its clients.

Since a single server can have multiple clients it would be fine to have a single TCP connection from my server to XMPP server. Is this possible? If yes, how to do this? I'm not familiar with XMPP yet.

Seems like XML stream is opened at the beginning and closed at the end, and closing tag doesn't have any indication which stream to close. So I assume I cannot have multiple XML streams over the same TCP connection. Please correct.

I can try to login multiple times with different usernames and specify "from" anywhere it's allowed. I noticed that on many places "from" attribute is optional and ejabberd can assume it probably based on connection, so I worry if this is possible.

도움이 되었습니까?

해결책

With normal client-to-server connections, each client must use a separate connection. Clients normally don't send their JID in the from attribute of the opening tag of the XML stream, but identify themselves during SASL authentication.

ejabberd supports the protocol described in XEP-0114, whereby your system can connect to the ejabberd as a "component", and send and receive messages on behalf of many different users. Depending on what you want to do, you may have to reimplement a lot of what ejabberd would do for you out of the box, e.g. presence subscriptions, roster management, routing of messages between users in your system. The only things ejabberd does for you in this case is sending you all messages to recipients in a certain domain, and route any outbound messages you send.

다른 팁

legoscia gave you some information about how you might make your server use a single TCP connection. Allow me to suggest some reasons why you would want separate TCP connections.

First, TCP connections are not terribly expensive. There are some rare times when they're too heavy (and you use UDP), but this is not one. XMPP authentication is far more expensive than TCP setup/teardown.

It's also not too expensive in other system resources. In a normal XMPP conversation, the client connects to the listener port on the server, the server spins off a worker process with its own port, and the two talk. Both client and server are using system-assigned port numbers, so if all your client connections are coming from a single machine you can have about 65,000 connections to the server. You'll run out of other resources (CPU, network bandwidth, etc) long before you run out of ports to use.

Second, one TCP connection per conversation is a convenient mapping. Ejabberd uses the one-process-per-connection idiom to isolate clients. If you put all your clients in a single TCP conversation, it will be a pain to split them out into separate processes. If they're all in one process, then you don't get concurrency between clients or process safety.

Finally, when debugging network problems, Wireshark can parse a TCP conversation and make it easy to read. If you have all your clients in one conversation, you don't get any of that benefit.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top