The socket is the intermediate software abstraction layer that is used to communicate with the TCP/IP protocol family, which is a group of connected ports. In design mode, the socket is actually a? Door-to-face mode, which hides complex TCP/IP protocol families in the socket after the port? For the user, a simple set of access ports is all, allowing the socket to organize the data to conform to the specified protocol.
? A scene in the life. You're going to call? A friend, dial first, a friend hears a phone call, and then you and your friend build a connection, you can talk. When the communication is over, hang up the phone and end the conversation.
Start with the server side. 1> the server-side first initializes the socket, then binds to the end port (BIND), to the end of the port (listen), the tune is blocked with accept, waiting for the client to connect. 2> at this point if a client initializes a socket and then connects to the server (connect),3> If the connection is successful, then the client-server connection is built. The client sends a data request, the server receives the request and processes the request, and then the connection succeeds, and the client-server connection is built. The client sends a data request, the server receives the request and processes the request, and then
Arc=send (fd,sztext,cnt,0);
Send the response data to the client, the client reads the data, and finally closes the connection. End of one interaction.
The client loses the IP address on the server side and sends the data, then presses the Send button, the server receives the data, and then responds to the client. The client reads the data of the response, which is displayed on the interface.
On the server side, the primary is to start the socket and the listener thread.
Server side? has been listening for a client connection, if there is a connection, processing the client's request, giving a response, and then continue listening.
Client:
Apple ISO Development: socket TCP/IP of Communication
Here's how to use it:
1, create the project.
2. Add Asyncsocket to the project.
3, add cfnetwork.framework to the project.
4. Implement Test class:
#import <UIKit/UIKit.h>
#import "AsyncSocket.h"
@interface Iphone_socketviewcontroller:uiviewcontroller {
Asyncsocket *asyncsocket; }
@end
IOS sockets based on tcp/udp of Communication
Category: iOS development 2013-12-03 15:10 1399 people reading reviews (0) Favorite reports
iOS Communication Socket Apple
There is already a well-written open source class library on the network Gcdasyncsocket and Gcdasyncudpsocket This is the GCD version of the Asyncsocket and Asyncudpsocket estimates to use a little bit usage is also very simple, similar to HTTP As long as you specify the IP and port of the server and then implement a variety of callbacks on the line, the original ecological implementation is groping .... Socket By default is the TCP protocol, after the creation of the communication between the two sockets will remain connected, unless manually close or for network reasons close, so this situation for the server is a certain resource consumption, this mode only adapts to the server small-scale access, Especially for high-real-time applications, such as video broadcast, call system, and HTTP is generally short-connected, after a single request, the client will be on the service end of the connection
HTTP is superior to the socket above the high-level protocol, and the socket is a comparison of the bottom of the communication, just set up a connection channel, the specific transmission of what kind of data, according to what format to transfer, you need to define, so this need to rewrite the definition of server and client should follow the rules, And HTTP has been used by previous definitions.
First go to GitHub's website to download the latest package, then take a look at the introduction. It's written in more detail.
Https://github.com/robbiehanson/CocoaAsyncSocket/wiki/Intro_GCDAsyncSocket
Many of the online posts are old versions. The authorities have introduced Gcdasyncsocket to replace the old Asyncsocket.
My project is No-arc, this frame only has the arc version. So after introducing the gcdasyncsocket. h and. m files, modify the properties of the project in Xcode.
1) Find the compiler for C/C++/OBJECTIVE-C option in "Build Settings" in targets. Change to Apple LLVM compiler 3 only if 3.0 or more
2) Find GCDASYNCSOCKET.M in "Build Phases" in "Compile sources", add parameter-fobj-arc
3) Introduction of Gcdasyncsocket required framework, cfnetwork and security these two
Communication http , TCP/IP with the Socket the difference between
1. TCP/IP connection
Mobile phone can use the network function is because the bottom of the mobile phone implementation of TCP/IP protocol, you can make the mobile phone terminal through the wireless network to establish a TCP connection. TCP protocol can provide an interface to the upper network, so that the transmission of the upper network data is based on the "No Difference" network. Setting up a TCP connection requires a "three-time handshake":
First handshake: The client sends a SYN packet (SYN=J) to the server and enters the Syn_send state, waiting for the server to confirm;
Second handshake: The server receives the SYN packet, it must confirm the customer's SYN (ACK=J+1), and also send itself a SYN packet (syn=k), that is, the Syn+ack packet, when the server enters the SYN_RECV state;
Third handshake: The client receives the server's Syn+ack packet, sends the acknowledgment packet ack (ACK=K+1) to the server, the packet is sent, the client and the server enter the established state, and the handshake is completed three times.
The data is not included in the packets that are delivered during the handshake, and the client and server formally begin transmitting the data after the three handshake is complete. Ideally, once a TCP connection is established, the TCP connection is maintained until either side of the communication actively closes the connection. When disconnected, both the server and the client can initiate a request to disconnect the TCP connection, and the disconnection process requires a "four handshake" (the process is not fine-grained, that is, the server interacts with the client and finally determines the disconnection).
2. HTTP connection
The HTTP protocol, the Hypertext Transfer Protocol (hypertext Transfer Protocol), is the foundation of Web networking and one of the most commonly used protocols for mobile networking, an application built on the TCP protocol.
The most notable feature of an HTTP connection is that each request sent by the client requires a server loopback response, and the connection is actively released after the request has ended. The process from establishing a connection to closing a connection is called a "one-time connection."
3.1 Socket (socket) concept
Socket (socket) is the cornerstone of communication and is the basic operating unit of network communication supporting TCP/IP protocol. It is an abstract representation of the endpoint in the network communication process and contains five kinds of information that must be used for network communication: the protocol that the connection uses, the IP address of the local host, the protocol port of the local process, the IP address of the remote host, and the protocol port of the remote process.
3.2 Establishing a socket connection
Establishing a socket connection requires at least one pair of sockets, one running on the client, called Clientsocket, and the other running on the server side, called ServerSocket.
The connection between sockets is divided into three steps: Server listening, client request, connection acknowledgement.
Server monitoring: Server-side sockets do not locate specific client sockets, but are waiting for the status of the connection, real-time monitoring network status, waiting for the client connection request.
Client request: Refers to the client's socket to make a connection request, to connect to the target is the server-side socket. To do this, the client's socket must first describe the socket of the server it is connecting to, indicate the address and port number of the server-side socket, and then make a connection request to the server-side socket.
Connection confirmation: When a server-side socket hears or receives a connection request from a client socket, it responds to a client socket request, establishes a new thread, sends a description of the server-side socket to the client, and once the client confirms the description, the two sides formally establish the connection. While the server-side socket continues to be in the listening state, it continues to receive connection requests from other client sockets.
4. Socket connection and TCP/IP connection
When you create a socket connection, you can specify the transport layer protocol used, which can support different transport layer protocols (TCP or UDP), which is a TCP connection when a connection is made using the TCP protocol.
? 5, socket connection and HTTP connection
In many cases, the server side is required to proactively push data to the client, keeping the client and server data in real time and in sync. At this point, if the two sides established a socket connection, the server can directly transfer the data to the client, if the two sides establish an HTTP connection, the server needs to wait until the client sends a request before the data can be sent back to the client, so the client periodically sends a connection request to the server, not only to remain online, It also asks the server if there is any new data, and if so, it passes the data to the client.
HTTP protocol is the application layer of the semantic
One is the engine (Socket), which provides the ability of network communication? One is the sedan (Http), which provides a concrete way
The communication between the two computers is nothing more than the data communication between the two ports, and what form will the concrete display ' is defined by different application layer protocols ' such as HTTP ' FTP ' ...?? The socket is a tool for developing port communication, and it needs to be lower.
Get and post this is the HTTP protocol two methods, in addition to head, delete and so on? There is an essential difference between the two methods, get has only one stream, the parameter is appended to the URL, the size of the number is strictly limited and can only be a string. Post parameters are passed through a different stream, not through the URL, so can be very large, can also pass binary data, such as file upload. In servlet development,
TCP/IP , Http , Socket the Difference
With a preliminary understanding, I know that the IP protocol corresponds to the network layer, the TCP protocol corresponds to the transport layer, and the HTTP protocol corresponds to the application layer,
”
And what we usually say the most socket is what, in fact, the socket is the TCP/IP protocol encapsulation, the socket itself is not a protocol, but a call interface (API).
With the socket, we can use the TCP/IP protocol.
In fact, the socket is not necessarily associated with the TCP/IP protocol.
The socket programming interface is designed to adapt to other network protocols as well.
So, the advent of sockets just makes it easier for programmers to use the TCP/IP protocol stack, which is an abstraction of the TCP/IP protocol.
This creates some of the most basic functional interfaces we know, such as Create, listen, connect, accept, send, read, write, and so on.
The network has a section on the socket and TCP/IP protocol relationship is relatively easy to understand:
"TCP/IP is just a stack of protocols, just like operating systems, which must be implemented in a specific way, as well as providing an external interface for operations."
CSDN has a comparative image of the description: HTTP is a sedan, provides a package or display the specific form of data; The socket is the engine that provides the ability to communicate over the network.
In fact, the transport layer TCP is based on the network layer of IP protocol, and the application layer of the HTTP protocol is based on the transport layer of the TCP protocol, and the socket itself is not a protocol, as stated above, it just provides a TCP or
The connection between sockets is divided into three steps: Server listening, client request, connection acknowledgement.
1, Server monitoring: Server-side sockets do not locate the specific client sockets, but in the status of waiting for the connection, real-time monitoring network status, waiting for the client connection request.
2, client request: Refers to the client socket to make a connection request, to connect to the target is the server-side socket.
To do this, the client's socket must first describe the socket of the server it is connecting to, indicate the address and port number of the server-side socket, and then make a connection request to the server-side socket.
3. Connection confirmation: When the server side socket is heard or received the connection request of the client socket, it responds to the request of the client socket, establishes a new thread, sends the description of the server end socket to the client, and once the client confirms the description, the two sides formally establish the connection.
While the server-side socket continues to be in the listening state, it continues to receive connection requests from other client sockets.
Third, the characteristics of HTTP links
The HTTP protocol is the Hypertext Transfer Protocol (Hypertexttransfer Protocol), which is web-linked
Four, the difference between TCP and UDP (the most test). It's getting rotten. I think--\\)
1, TCP is a link-oriented, although the security of the network instability characteristics determine how many times the handshake can not guarantee the reliability of the connection, but the TCP three handshake at a minimum (in fact, to a large extent guaranteed) to ensure the reliability of the connection;
And UDP is not connection-oriented, UDP transmission data before the connection with the other, the docking received data does not send a confirmation signal, the sender does not know whether the data will be received correctly, of course, there is no need to resend, so that UDP is a non-connected, unreliable data transmission protocol.
2, also due to 1 of the characteristics of the said, so that the cost of UDP smaller data transmission rate is higher, because there is no need to send and receive data confirmation, so UDP real-time better.
Know the difference between TCP and UDP, it is not difficult to understand why the use of TCP transmission protocol MSN than UDP transmission file slow, but can not say that QQ communication is not safe,
Because programmers can manually authenticate UDP data, such as the sender of each packet number and then by the receiver to verify ah what?
Even so, UDP does not have a TCP-like "three-time handshake" on the package of the underlying protocol to achieve the transmission efficiency that TCP cannot achieve.
iOS app is very focused on user experience, not only requires the interface design is reasonable and beautiful, but also requires a variety of UI responsiveness, I believe we are the kind of a drag on Kaka TableView application is not a good impression. Remember 12306, that speed, I believe we can not stand it. to improve IOS running speed, I'll introduce some of the things I've practiced to provide IOS procedures to run the efficiency of the method, share with you, hoping to get more feedback and suggestions.
1 , calculate code run time: Believe the data, do not believe too much feeling.
2 and use performance analysis tools.
4 do not use too many Xib Xib Slow Compile speed , there is a Xib the process of converting to code
5. for TableView, reuse cell, reduce the workload of cell initialization, delay load;
6. use Autoreleasepool in the thread .
7 , and put some less important tasks Idle when running.
8 , do not in Viewwillappear Time -consuming operation.
9 , using multithreading to delay loading resources. Placeholder , async , main thread
Ten Use Cache Space Change Time . cache is a common space-time-to-deliver performance that can be used on quite a number of occasions.
ios6,7 the time
1. According to the traditional new version of iOS will appear with the new iOS device, that is, the new iphone released next month, but in June when Apple held the conference has released the BATE version of IOS6, if you have a developer account, you can update to the latest beta version, If not next month also bound to wait until the official version IOS6
IOS6 new Features
Every time the iOS big version of the update, will bring some new things, for developers, pros and cons. The advantage is that a lot of new properties, controls and APIs have been added, and developers have more privileges and can easily implement more features. The downside is that some old API interfaces may be abolished, and more adaptation and compatibility is required. Consult the IOS6 SDK and some of the documentation on the web through some of the experience of your own development process. This paper summarizes the following new features of the IOS6 system, which makes it easy for us to make a comparative reference in the subsequent development process.
a about memory warnings
Viewdidunload,viewwillunload These two system callbacks were abolished in ios6, and related processing was performed in didreceivememorywarning when a memory warning was received.
two about screen rotation
The same IOS6 abolished the setting interface of the shouldautorotatetointerfaceorientation screen. The rotation property must be set in two new interfaces: Shouldautorotate
Supportedinterfaceorientations
The processing after the rotation event is received, also in Willrotatetointerfaceorientation, and didrotatefrominterfaceorientation.
three Uiswitch
IOS6, the following properties have been added to set the color of the switch and the background map
@property (nonatomic, retain) Uicolor*tintcolor;
@property (nonatomic, retain) Uicolor*thumbtintcolor;
@property (nonatomic, retain) uiimage*onimage;
@property (nonatomic, retain) UIImage *offimage;
Four Uinavigationbar
IOS6 new, set the properties of the shadow picture
@property (nonatomic, retain) uiimage*shadowimage;
Five UIImage
You can set the scale size of the picture under IOS6.
+ (UIImage *) Imagewithdata: (NSData *) Data scale: (cgfloat) scale;
-(ID) Initwithdata: (NSData *) Data scale: (cgfloat) scale;
Six Uirefreshcontrol
Before Apple officially did not have a ready to pull the refresh of the control, are to implement or use a relatively mature open source library. This time, IOS6 Apple to join the Uirefreshcontrol, with UITableView Direct implementation of the drop-down refresh. However, to ensure compatibility, it is not recommended to use this control at this time.
Seven Uicollectionview
New collection controls, application scenarios like photo walls, waterfall streams, etc. There have been many open-source libraries in GitHub that have implemented the functionality of this control.
IOS7 new Features
New UI Design
IOS7 The biggest change is the UI design, perhaps you will say UI design "This is the designer should pay attention to things, not the developers, we just need to replace the image." Then you are wrong. Changes in the UI will inevitably bring about changes in usage habits and patterns, how to use the IOS7 UI, and how to make your application more relevant to the new system, which is something to consider. It's also worth noting that apps packaged with the IOS7 SDK (now available only in XCODE5 Preview) will automatically use IOS7 's new interface when run on IOS7, so the legacy app may need to make significant adjustments to the new interface. The Human interface documentation for the UI elements used in the specific iOS7 can be found here (it should be a developer account).
to summarize, it seems that the new UI There are several improvements to this change:
1. status bar, navigation bar and app actual content no longer bounds: The system comes with applications that no longer differentiate between the status bar and the navigation bar, but with a uniform color for simplicity. This is also a trend.
2. Baritem All the text of the button : This is quite resolute, all the navigation and toolbar buttons are canceled to materialize, the original text (such as "Edit", "done", etc.) to the simple text, The original icons (such as new or deleted) have also been simplified.
3. Program Open added Animation: A zoom in from the main interface to the location of the icon, while displaying the app's loading interface.
The spring breeze and green California shore, have changed another year. WWDC Keynote, the new iOS development journey also opens. What do developers need to know behind the big changes in the IOS7 interface? As I did last year, I'll start with a brief overview of what I personally think developers need to focus on and learn in IOS7, and then explore the chapters of their own interest. Plan to inherit the form of notes similar to WWDC2012 and hope that the domestic developers will be helpful.
At last
Of course there are some other minor changes, including the addition of the attachment button in the Messageui, Xcode started to support the module, and so on. A complete list of iOS7 new features can be found here (for the time being, you should also need a developer account). The last good news is that Apple has slowed down the rate of obsolete APIs, and this version has no particularly important API labeled Deprecated,Cheers.
Although Arc is launched with IOS5, the application can still support iOS4.3 after using ARC because the implementation mechanism of ARC is completed at compile time. It is important to note that if you want to support iOS4.3 in the case of arc opening, you need to change the weak keyword to __unsafe_unretained, and there are some details that need to be dealt with, and I will not expand it here.
Network-Performance Tuning