Alibabacloud.com offers a wide variety of articles about socket operation on non socket, easily find your socket operation on non socket information here online.
Erlang R17 introduces the new socket option {active, N}. Together with {active, once}, it provides traffic control for the application layer. Why does the option {active, once} effectively suppress a large number of socket messages?
We know that {active, once} has to reset the active option every time it receives the packet to continue receiving erlang message no
confirm the fin. Its reception is also passed as a file terminator to the application process, because the receive of fin means that the application process can no longer receive additional data on the corresponding connection;
After some time, the application process that receives the file terminator calls close to close its socket. This causes its TCP to send also a fin N;
This fin is received by
specify the protocol to use, the general setting is 0, using the default connection method. socket is a function, then he also has a return value, when the socket successfully created, return socket, failed to return "1"; error code is written in "ERRNO";To create a socket:#include #include #include int soc_fd_tcp;int
LISTENING status. Next, we only need to run the client program to connect. Code on
Now the client is connected to the server.
Case 2: Code details
// Set some basic variables $ host = "192.168.1.99"; $ port = 1234; // set the timeout value set_time_limit (0 ); // create a Socket $ socket = socket_create (AF_INET, SOCK_STREAM, 0) or die ("cocould not createsocket \ n
basic variables $ host = "192.168.1.99"; $ port = 1234; // set the timeout value set_time_limit (0 ); // create a Socket $ socket = socket_create (AF_INET, SOCK_STREAM, 0) or die ("cocould not createsocket \ n "); // bind the Socket to the port $ result = socket_bind ($ socket
when doing socket programming, and the following functions provide address type conversions.
#include
The INET_ADDR function converts the IPV4 address represented by a dotted decimal string to the IPV4 address represented by a network byte-ordered integer. Returns Inaddr_none when it fails.
The Inet_aton function completes inet_addr the same function, but the transformation result exists in the INP point IN_ADDR address structure body.
The Inet_nto
ntohl (uint32_t netlong); uint16_t ntohs (uint16_t netshort);/** Note: h stands for (local) host; n stands for network; s stands for short; l stands for long ;*/
// Test the Conversion Result: int main () {int localeData = 0x12345678; char * p = (char *) localeData; printf ("Begin: % 0x % 0x % 0x % 0x \ n ", p [0], p [1], p [2], p [3]); // convert local bytes to network bytes int inetData = htonl (localeD
@Desp: Processes communicate with UNIX domain socket */#include "Domain_soc
Ket.h "#define PATH"/home/useless "/* process communicates through the domain-Example: parent-child process, one send, one receive */int main (void) {int pid;
/* The child process is used to send the message */if ((PID = fork ()) = = 0) {int fd, counter = 0;
Char Send_buffer[msg_size];
struct Sockaddr_un addr;
if (fd = Init_send_socket (addr, PATH)) > 0)
discuss it for the moment. I will only give you a reference article.
Http://www.zend.com/pecl/tutorials/sockets.php
2. Use PHP socket extension
Server code:
Client code:
Start the server using cli:
Php server. php
Note the socket_read function here:An optional type parameter is a named constant:PHP_BINARY_READ-use the system recv () function. Security for reading binary data. (In PHP> "default = 4.1.0)PHP_NORMAL_READ-stop at \
socket; if the socket is bound to a local address, then, only the destination address in the IP address header of the received data is equal to the local address, and the received data is copied to the socket. If the socket defines the remote address, only when the source address in the received data IP header matches
IntroducedA C + + socket client LibraryHttp://www.rudeserver.com/socket/index.htmlThe rudesocket™open Source C + + Socket Library provides a simple to use interface for creating and using client S Ockets. You can connect to the destination server through an unlimited number of chainable proxies, SOCKS4 and SOCKS5 servers if a Nonymity or security is a priority. S
; 0) {
There might is more data, and so store the "data received so far."
State.sb.Append (Encoding.ASCII.GetString (
State.buffer,0,bytesread));
Check for End-of-file tag. If It is not there, read
More data.
Content = State.sb.ToString ();
if (content). IndexOf ("All of the data has been read from the
Client. Display it on the console.
Console.WriteLine ("Read {0} bytes from socket.") \ n Data: {1} ",
Cont
started and is still in progress.
If the data receiving buffer (dwReceiveDataLength is not 0) is provided, the overlapping operation of AcceptEx () delivery will not be completed until the connection is received and data is read. You can use the SO_CONNECT_TIME option of getsockopt to check whether a connection has been accepted. If it has been accepted, you can obtain how long the connection has been established (in seconds). If the socket is not co
are executed on the server. X. php is a file executed on the client.
Xx. php
// Set some basic variablesGlobal $ lat, $ lnt;$ Host = "192.168.1.110 ";$ Port = 8080;// Set the timeout valueSet_time_limit (0 );// Create a Socket$ CommonProtocol = getprotobyname ("tcp ");$ Socket = socket_create (AF_INET, SOCK_STREAM, $ commonProtocol );// Bind the Socket to the
bytesRead = handler. EndReceive (ar );If (bytesRead> 0 ){// There might be more data, so store the data stored Ed so far.State. sb. Append (Encoding. ASCII. GetString (State. buffer, 0, bytesRead ));// Check for end-of-file tag. If it is not there, read// More data.Content = state. sb. ToString ();If (content. IndexOf ("// All the data has been read from// Client. Display it on the console.Console. WriteLine ("Read {0} bytes from socket. \
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.