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.
($ socket, 8192) {48 echo" received server return message successful! \ N "; 49 echo" received content: ", $ out; 50} 51 52 53 echo" disable SOCKET... \ n "; 54 socket_close ($ socket); 55 echo" close OK \ n "; 56?>
Now the c
Invalid_socket is returned if it fails. The first parameter of the function specifies a stream socket in the listening state; the operating system uses the second parameter to return the address structure of the newly created socket; the operating system uses the third parameter to return the length of the address structure of the newly created socket.*/if (Inva
connected" on the server-side screen.
C, the server checks the buffer, if there is data in the buffer, it will send the data to the connected computer.It then sends the receiving information of the data, and once it accepts the information, it saves the information to the data and lets the connected computer know the information and finally closes the connection.
D, after the connection is closed, the server starts processing the next connection.
View source Copy to Clipboard printing help
Ge
is required to transfer data over the Internet.
Several byte order conversion functions:
Htons ()--"Host to Network short"; HTONL ()--"Host to Network Long"
Ntohs ()--"Network to Host short"; Ntohl ()--"Network to Host Long"
Here, h denotes "host", N means "network", s means "short", and L means "long".
------------
(3) Listen () function:
1) Prototypes:
int listen (int sockfd, int backlog);
2) Function:
Call Listen () to listen to the
www.ptpress.com.cn.
Package mysocket;
Import java.net.*;
Import java.io.*;
public class MyConnection2
{public
static void Main (string[] args) throws Exception
{
socket socket = NE W Socket ("www.ptpress.com.cn",);
Sending data to a server-side program
outputstream OPS = Socket.getoutputstream ();
OutputStreamWriter OPSW = new Ou
' + remote_ip
Now that we know the IP address of the server, we can use the connection function connect to a specific port of the IP address. The following example connects to port 80 (the default port of the HTTP service):
#Connect to remote servers.connect((remote_ip , port)) print 'Socket Connected to ' + host + ' on ip ' + remote_ip
Run the program:
$ python client.pySocket createdIp of remote host www.google.com is 173.194.38.145Socket Connected
httpd in prefork mode, each sub-process is both a listener and a worker. When each client initiates a connection request, the sub-process receives the request during the listener, and releases the listening socket so that other sub-processes can listen to the socket. After multiple rounds, a new connection socket is generated through the accpet () function, so t
;/*Create New Stream Socket*/sock= Socket (Af_inet, Sock_stream,0 );/*Disable the Nagle (TCP No Delay) algorithm*/Flag=1; RET= setsockopt (sock, Ipproto_tcp, Tcp_nodelay, (Char*) flag,sizeof(flag));if(ret = =-1) {printf ("couldn ' t setsockopt (tcp_nodelay) \ n"); Exit (-1);}Tip: Experiments with samba show that disabling the Nagle algorithm can almost double the
module is also very young and many places are immature, the relevant reference documentation is very small: (
I am also in the study, so for the time being not specifically discussed it, only to give you a reference to the article
http://www.zend.com/pecl/tutorials/sockets.php
2. Using the PHP socket extension
Server-side code:
?
123456789101112131415161718192021st22232425262728293031323334353637383940414243444546
/** * File
PHP Socket Programming Process detailed
Introduced
Sockets are used for interprocess communication. Interprocess communication is typically based on a client-server model. At this point, the client-server is an application that can interact with each other. The interaction between the client and the server requires a connection. Socket programming is responsible for establishing an interactive connection
the server's return message! \ N "; echo" accept the following content: ", $ out;} echo" close SOCKET... \ n "; socket_close ($ socket); echo" close OK \ n ";?>
Run the server and client to return information. now the client is connected to the server.Code details
// Set s
) to connect a serversocket (S), so wrote two simple programs and analysis, features a dataacceptserver, You can create 4444 ports, can accept up to 50 connections, two Datasender, create long connections, and know how to send Byebye. For convenience, use UTF-8 character streams. The procedure is as follows://server Importjava.io.BufferedReader; Importjava.io.IOException; Importjava.io.InputStreamReader; Importjava.io.OutputStreamWriter; Importjava.io.PrintWriter; Importjava.net.ServerSocket; Im
Hidden trouble 1. Ignore return statusThe first pitfall is obvious, but it's the easiest mistake for a novice developer to make. If you ignore the return state of a function, you may get lost when they fail or partially succeed. This, in turn, can spread errors, making it difficult to locate the source of the problem.Captures and checks each return state, rather than ignoring them. Consider the example shown in Listing 1, a socket send function.Listin
calls return immediately.In addition, in many cases, Socket programming is implemented on the client and server based on different situations, and the application program is compiled on the client to send requests to the specified port on the server, at the same time, the preparation of the server application to process the request has been mentioned in the above description; of course, not all Socket prog
we introduce the process of the four handshake release connection in the socket, please look at the following figure:
Figure 2 TCP Four-time handshake sent in socket
The diagram process is as follows:
An application process first calls close to actively shut down the connection, at which point TCP sends a FIN M;
The other end receives the fin m and performs a passive shutdown to confirm the f
Introduced
The socket is used for interprocess communication. Interprocess communication is typically based on the client-server side model. At this point, the client-server side is an application that can interact with one another. The interaction between the client and the server needs to be connected. Socket programming is responsible for establishing an interactive connection between applications.
In
in the form. "|" in the string The previous sections are specific commands, including Conn, CHAT, PRIV, gone four types. The conn command creates a new client connection, sends an existing list of users to a new user and informs other users that a new user is joining. The chat command sends new information to all users. The Priv command sends a WHISPER message to a user. The Gone command removes a left user from the list of users and informs other users that So-and-so has left. At the same time
connection, when TCP sends a FIN M;
After the other end receives fin m, perform a passive shutdown to 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 cau
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.