Instant Messaging (IM), in the arena of iOS is already an old man, I this small cyclone is also a long time to patrol the mountain, I know that there is instant communication this monster, has been more or less contact with some, in the creation of the app when used, Ah, said the feeling to digress, How the waves roll in my head. Not good, only the beginning of two sentences, ~ ~ (>_<) ~ ~ Endure!! To get back to the point, I know that im useful cocoaasyncsocket also have xmppframework realized, of course, there are now also most of the access ring letter. Some things can not cover up, may be many peers and I, feel you know more and more, the more you will feel like an illiterate, actually do not understand really a lot of many, there are so many waiting for you to learn!! At this time decisive will introduce a few words have philosophical meaning, comfort yourself. For example, "You must work hard, but don't worry." O (∩_∩) o haha ~, feel will be Jane book Children Dozen, Can't pretend forced. In front of that sentence is a book in the editor of book title, by the way also recommend to everyone to see, edify sentiment bar.
Should many peers also know these three parties, know how they are used, if also clear the knowledge of the bottom of the network protocol, in fact, I envy, after all, is not a computer professional, do not know much, but also that there are many and I, halfway decent children, I still suggest there is time to learn about the bottom of these, The most basic thing. I am also constantly learning to try and summarize, I believe these underlying foundation is you to the great God Road, essential, yes, yes, indispensable!
In this article we will talk about how to build a mock chat framework and how to build a OpenFire server to achieve a simulated chat.
What should I do?
Here are some things you should be able to help people, you can take a good look, of course, a lot of theoretical things, you have to spend time, if you have to have time ([email protected][email protected]=)!!
A: Socket communication take time to understand, before touching the cocoaasyncsocket, remember that it is necessary to understand the principle, because Cocoaasyncsocket is the Apple Cfnetwork package, so you know Cfnetwork is also good drop.
Two: XMPP protocol know what is XMPP, I know there may be many just px out of the baby, also often hear will use XMPP to do instant messaging, then you know what is XMPP exactly? Know what he is, OK, some of the classes and methods used in it are all used here in Xmppframework.
Three: Ring letter, I think it really is to the front-end developers to save a lot of great effort, in fact, there is a detailed development of the document is the difficulty of the things are down 10,000 points. It also has UI chat framework, what you have to do is to get it into your app inside, there is nothing to say, but also said the official document. O (∩_∩) o haha ~
What you want to see below is actually a lot!
or in order to come, we first talk about the whole chat frame to build a train of thought (the other side does not want to talk to you, and to you lost a bunch of high-imitation chat framework source I need you star!). I also look at the Cocoachina on the big God Step by step analysis, imitation write, in the source code inside comments full, you have to look seriously, should be no problem!
Say the above framework, the use of the Controller 1 to add Controller 2 and Controller 3, the Controller 1 is a normal controller, he is the Controller 2 and Controller 3 agent, Controller 2 is a tableviewcontroller used to display our chat messages. Controller 3 is mainly to control the following keyboard part of the thing, the keyboard part actually feel should be the whole key, but also have keyboard input, voice, expression, more of these parts of the composition. The whole main idea is that the event on Controller 3 is the agent Controller 1 response after the click, and then in controller 1 to change the controller 2 to display things.
A simple list of git on the source of a general, convenient for everyone to see it.
The whole chat frame in the Chats folder inside, the chat folder under the Models inside is sure to be all kinds of model, under the Views folder, the Message is stored in a variety of cells to display, Box storage is a variety of controller 3 inside the interface.
Controller 1:xydjviewcontroller Controller 2:zxchatmessagecontroller controller 3:zxchatboxcontroller
In the code, there is a detailed comment description Click download chat frame source code
Talk about the chat server!
Before the project useful to Asyncsocket, ring letter not much to say, say more also then the egg, you can say more than the official document details? O (∩_∩) o haha. It's enough to look at the document and hit the keyboard, so let's talk about Xmppframework. If you have no backstage and no server, play it yourself, I use OpenFire server and Mysql database as well as Spark or Adium front end.
For OpenFire server and Mysql database installation configuration, everyone go to see this openfire configuration installation
According to my own configuration of the situation, to everyone talk about the following points of attention! First remember to configure the installation database, and then configure the installation server! Of course it's not dead, it's just a reasonable order!
There are a few points to note when configuring the database:
Under this new Connections to add a new database, when configuring the server, we must pay attention to:
One: You have to install the Java jdk. I've also tried to install the latest Java environment, and it turns out that you still have to install the JDK. JAVA/JDK Link installs 8u91 version of MAC OSX.
Second: If the failure is still open. May be the issue of permissions, enter in the terminal:
sudo chmod-r 777/usr/local/openfire/bin
sudo su
Cd/usr/local/openfire/bin
Export java_home= '/usr/libexec/java_home '
Echo $JAVA _home/library/java/javavirtualmachines/jdk1.8.0_51.jdk/contents/home
Cd/usr/local/openfire/bin
./openfire.sh
Third: When linking the database:
User name and password, just fill in the user name and password that you just started in the configuration database. Corresponds to the 1 2 above.
There is also this database URL, you selected on the top. After MySQL, there will be an automatic fill, where [host-name] is the time you configure the database 3 address, [Database-name] is the time you configure the database in the new Connections created in the name of the database, not Connections's name, pay attention.
Spark or Adium Everyone click on the link to download. You can download both, create two users, log in and chat with friends to try to see if the server has any problems. There are problems can be added to my QQ chat, qq my blog Park home has.
What about the results?
First create two users, chat two days to see our server OK, the result it is no problem.
So what do we do with xmppframework?
About Xmppframework specific methods how to use, I will not say more, you can find too many articles to learn. In the above framework, a simple test of whether or not to receive the message, the proof is no problem.
By the way, this XMPP received the data format is XML format, some babies may be exposed to the JSON format of data more, XML format of data parsing is not familiar with, link XML parsing to everyone, the interpretation of data analysis is very detailed, write is also awesome!!
It's over?
Well, it's almost over here, it must be explained that the above XMPP test code has not been added to the framework we wrote, is written in the Xwviewcontroller inside, we can download the code to improve their own, there is time I will add it in.
Give everyone a mouthful of chicken soup affixed to our company walls, "You do not work hard, no one can give you the life you want!" ", the essay wrote the question of the place everyone comments, in the homepage also has my QQ can add QQ exchange ...
Li Hongqiang About Instant Messaging