Suppose that I have to write a UDP server which should receive authentication token for each client in the first message and then receive different data after some period of time. This UDP server should obviously check whether certain client authenticated previously or not. How should I do it? Should I store "authenticated" flag for each (IP addr, port) pair? Is it ok? If so, what will happen if several clients will have the same IP address (for example, they share it from the same internet provider)?
I think you can't. You'll need to have the token in each message. Multiple requests can come from the same IP, such as a client connecting from behind a NAT.
This a rare case where you might want to use multiple UDP sockets at the server and connect() each of them to one authenticated client, so that you can only receive further messages on each one from each authenticated client. You'll have to send the first reply via hat socket,a denture client will have to be written to adjust its destination accordingly after receiving the first reply.
Related
I am programming an IRC gateway to another protocol, and I want my IRC server (the gateway) to notify the IRC client when other users are connected or disconnected.
This feature is supported by my IRC client (Quassel) : it shows me when a user set himself as /away, but I can't figure out what command my IRC server must send to set/unset user presence.
You ideally implement the IRCv3 spec away-notify: http://ircv3.net/specs/extensions/away-notify-3.1.html
Otherwise your client has to spam WHO polls often to get the latest status of users.
As i wrote in another post ("Symmetry Procedure" in NFC P2P LLCP) i'm currently trying to implement the LLCP & SNEP protocol on a PN532 chip.
The question i had in the other post was about the Symmetry Procedure as defined in LLCP which allows
to actually bypass the original Initiator / Target roles (command / response) i.e. gives each peer device
the change to send a message at any time.
If i got it right, the SNEP-protocol defines a Client / Server approach. The role is actually defined at
the LLCP-level when one device (client) sends a CONN-PDU to the peer device (server).
Afterwards the client can send NDEF-messages to the server by using a "PUT Request" as defined in SNEP.
Let's assume now, the client has sent it's NDEF message to the server and - depending on the application -
the peer device which currently acts as a server wants to send a new (not a response) NDEF message back to the
current client.
My assumption is that the current server would send a new CONN-PDU to the current client and in case this succeeds,
both both devices change their initial roles i.e. the initial client becomes now the server etc.
What happens to the initially established connection ? Will it be closed or can still exist in parallel to the new one ?
In addition (if my assumption from above is correct), is it also necessary on the NFC MAC level that the Client / Server change
mandates also a change of the Initiator / Target roles or can both devices stay in their initial (MAC) modes ?
Thanks a lot !
If i got it right, the SNEP-protocol defines a Client / Server
approach. The role is actually defined at the LLCP-level when one
device (client) sends a CONN-PDU to the peer device (server).
No, that's not how it works. The role is not defined that way. It is not obvious from the specification, but each peer usually is a client and a server at the same time.
Note that the spec section 6.1 "Functional Description" defines the following default behavior:
The default server SHALL NOT accept Get requests.
That means, that a client is in general not allowed to request NDEF messages. The client is supposed to push it's own message if available.
The usual message flow in SNEP looks like this:
Initial state: LLCP link is down. Each peer has a SNEP server registered and waiting for connections.
On LLCP connect: Each peer that wants to send a message tries to connect to the opposing SNEP server using it's own SNEP client.
On SNEP connect the SNEP server will: wait for a SNEP PUT command. It can then either accept the message or reject it:
On SNEP connect the SNEP client will: send out a PUT command along with it's NDEF data.
Once each side has transmitted it's message (if they wanted to) they just leave the SNEP connections open. There is no proper way to close this connection anyway and there is also no cost associated with it. Each client can - at any time - always send an additional PUT request if they want to. This can be useful to esablish an bidirectional data-flow over SNEP.
Android won't allow this bidirectinal data-flow because they somewhat dumbed down SNEP a bit and don't allow a second message to be sent, but they will happily accept additional messages passed to it.
I'm trying to understand the differences between AMQP and XMPP and among other things I don't really understand if XMPP works like it had Queues.
When you send a message to various clients what happen if one of them is down? The server enqueues the message up to the client is up again or how does it work?
Thanks
It depends on the XMPP server implementation how messages and iq's are handeld when the JID is offline. Section 11.1 of RFC 3921:
Else if the JID is of the form and there are no
available resources associated with the user, how the stanza is
handled depends on the stanza type:
...
For message stanzas, the server MAY choose to store the stanza on
behalf of the user and deliver it when the user next becomes
available, or forward the message to the user via some other means
(e.g., to the user's email account). However, if offline message
storage or message forwarding is not enabled, the server MUST return
to the sender a stanza error. (Note: Offline
message storage and message forwarding are not defined in XMPP, since
they are strictly a matter of implementation and service
provisioning.)
For IQ stanzas, the server itself MUST reply on behalf of the user
with either an IQ result or an IQ error. Specifically, if the
semantics of the qualifying namespace define a reply that the server
can provide, the server MUST reply to the stanza on behalf of the
user; if not, the server MUST reply with a
stanza error.
I don't know enough about SIP. As far as I know SIP can not be used in LAN. But it's features are very good. I want to use it for a LAN messenger (with video conference facilities).
Is there any way of using SIP in LAN network ?
The SIP protocol can be used over any reliable transport (TCP, XMPP, instant messaging channel, etc...) to a service (e.g. a server such as a SIP proxy) that knows how to route the SIP INVITE message from the caller to the callee. e.g. If you send an INVITE to bob#foobar.com, there's needs to be a service that knows how to find "bob" and deliver the message. Likewise, when Bob sends back his response messages back, the messages need to route back to the caller who sent the original INVITE.
And you can do SIP without a server - provided the computer already have a connection (direct or indirect) to the other computer intended for the call.
But SIP isn't anything special. If you were to invent your own video conferencing protocol, it would probably look a lot like SIP. SIP's primary job is for both sides of a call to exchange IP/port candidates for connecting directly in addition to codec and bandwidth negotiation data.
After the SIP messages are exchanged, ICE/STUN/TURN take over and RTP packets typically flow. SIP isn't used in the call except to end the call.
What are you really trying to do anyway?
Thread is Old but still I would like to contribute to this. There are various SIP server like http://www.officesip.com/index.html which works in LAN and can be connected to hardware phone too and soft client also.
Jitsi is open source cross platform SIP/xmpp client:https://jitsi.org/
And if you want to XMPP server Openfire is the best:http://www.igniterealtime.org/projects/openfire/
I hope this will definitely help someone..!
I am basically writing a XMPP client to automatically reply to "specific" chat messages.
My setup is like this:
I have pidgin running on my machine configured to run with an account x#xyz.com.
I have my own jabber client configured to run with the same account x#xyz.com.
There could be other XMPP clients .
Here is my requirement:
I am trying to automate certain kind of messages that I receive on gtalk. So whenever I receive a specific message eg: "How are you" , my own XMPP client should reply automatically with say "fine". How are you". All messages sent (before and after my client replies) to x#xyz.com but should be received by all clients (my own client does not have a UI and can only respond to specific messages.).
Now I have already coded my client to reply automatically. This works fine. But the problem I am facing is that as soon as I reply (I use the smack library), all subsequent messages that are sent to x#xyz.com are received only by my XMPP client. This is obviously a problem as my own client is quite dump and does not have a UI, so I don't get to see the rest of the messages sent to me, thereby making me "lose" messages.
I have observed the same behavior with other XMPP clients as well. Now the question is, is this is a requirement of XMPP (I am sorry but I haven't read XMPP protocol too well). Is it possible to code an XMPP client to send a reply to a user and still be able to receive all subsequent messages in all clients currently listening for messages? Making my client a full fledged XMPP client is a solution, but I don't want to go that route.
I hope my question is clear.
You may have to set a negative presence priority for your bot..
First thing to know is that in XMPP protocol every client is supposed to have a full JID. This is a bare JID - in your case x#xyz.com with a resource in the end e.g. x#xyz.com/pidgin or x#xyz.com/home (where /pidgin and /home are the resource). This is a part of how routing messages to different clients is supposed to be achieved.
Then there are the presence stanzas. When going online a client usually sends a presence stanza to the server. This informs about e.g. if the client is available for chat or away for lunch. Along with this information can be sent a priority. When there are more than one clients connected the one with the highest priority will receive the messages sent to the bare JID (e.g. ClientA(prio=50) and ClientB(prio=60) -> ClientB receives the messages sent to x#xyz.com). But there are also negative priorities. A priority less than 0 states that this client should never be sent any messages. Such a stanza might look like this
<presence from="x#xyz.com/bot">
<priority>-1</priority>
</presence>
This may fit your case. Please keep in mind it also depends on the XMPP server where your account is located, which may or may have not fully implemented this part of the protocol.
So to summarize: I recommend you to look through the Smack API how to set a presence and set the priority to <0 for your bot client right after it connected.