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.
("receivedConnection from % s/n ", inet_ntoa (remote_addr.sin_addr ));If (! Fork ()){/*Child Process Code segment */If (send (client_fd, "Hello, you are connected! /N ", 26, 0) =-1)Perror ("send error! ");Close (client_fd );Exit (0 ); }Close (client_fd );} }}The workflow of the server is as follows: first call the socket function to create a
# Connect to remote serverS. connect (remote_ip, port ))
Print 'socket Ted CTED to '+ host + 'on ip' + remote_ip
# Send some data to remote serverMessage = "GET/HTTP/1.1 \ r \ n"
Try:# Set the whole stringS. sendall (message)Failed t socket. error:# Send failedPrint 'send failed'Sys. exit ()
Print 'message send successfully'
In the preceding example, connect to
(int sockfd, const struct sockaddr * addr,Socklen_t addrlen );
Remember that the value must be addrlen.
Accept socklen_t * addrlen is a pointer
I thought they were the same, and the results were adjusted for an hour.
You still need to work hard.
Layman c ++ simple code socket communication
# Include "stdafx. h"# Include # Include # Include # Define PORT 5000Int main (int argc, char * argv []){Int port = PORT;WSADATA wsaData;
Sock_streamProto defaults to 0, and we don't usually have a relationship.To create a TCP socket instanceIn [6]: Import Socketin [7]: S=socket.socket (socket.af_inet,socket. SOCK_STREAM)OK, with the socket instance, you can use many of the socket instance methods. What do these methods have?| Methods of
of code is the code in the program where I implement the communication:
1. 2. Set_time_limit (0);3. $address = "127.0.0.1";4. Ob_implicit_flush ();5./*6. * Created on 2009-9-147. *8. * To change the template of this generated file go9. * Window-preferences-phpeclipse-php-code Templates10. */11. $port = ' 8083 ';13. if ($sock = Socket_create (Af_inet, Sock_stream, sol_tcp)) echo "Socket_create () Failed:reason:". Socket_strerror ($sock). "\ n";16.}17
PHP uses socket to send HTTP requests, and phpsocket to send requests. PHP uses socket to send HTTP requests. phpsocket to send requests this article describes how PHP uses socket to send HTTP requests. For your reference, the details are as follows: so PHP uses socket to send HTTP requests, and phpsocket to send reque
function to receive the request to send SYN K to the client, ACK j+ 1, then accept into the blocking state, the client receives the server SYN K, after the ACK j+1, then connect returns, and the Syn K Confirmation, the server received an ACK k+1, accept return, this three times the handshake is completed, the connection is established.Summary: The client's connect returns in the second time of the three handshake, while the server-side accept is returned for the third time in the three-time han
detailed
Set some basic variables
$host = "192.168.1.99";
$port = 1234;
Set timeout time
set_time_limit (0);
Create a socket
$socket = socket_create (af_inet, sock_stream, 0) or die ("could not createsocket\n");
Bind socket to port
$result = Socket_bind ($socket, $h
Socket programming, socket
I. Data Types and related functions of socket addresses
Socket API is an abstract network programming interface that is applicable to various underlying network protocols, such as IPv4, IPv6, and UNIX Domain Socket. However, the address formats of
module documentation provided in the echoserver is used pipe, to see it.Echoclient Code AnalysisEchoclient.js: var net = require ("NET"), var readline = require (' ReadLine '); Console.log (' type ' "Exit" or "quit" to quit. '); /sock is an instance of net. Socketvar sock = Net.connect ({port:7}, function () {console.log (' server Connected '); Sock.setencoding (' UTF8 '); Sock.write (' Hello Echo server\r\n ');}); Sock.on (' Data ', function (dat
socketphp
The relevant code is as follows, $socket =socket_create (Af_inet,sock_stream, $commonProtocol)
or die("cannot create socket\n"); //绑定socket到端口 $result=socket_bind($socket,$host,$port) or die("cannot bind port to socket
break (\ r \ n) symbol to the end of each command as the separator. For string processing, the easiest way to implement this method is to useStreamwriterObject andStreamreaderObject. Used for sendingStreamwriterThe writeline () method of the object writes the sent string to the network stream. The receiver only needs to callStreamreaderThe Readline () method of the object reads the string using the carriage return linefeed as the separator from the n
the packet capture tool to obtain the domain name or IP address of the server. The port http protocol is generally 80 public static string SocketSendReceive (string request, string server, int port) {try {Byte [] bytesSent = Encoding. ASCII. getBytes (request); Byte [] bytesReceived = new Byte [655350]; // create a connection Socket s = ConnectSocket (server, port); if (s = null) return ("Connection failed"); // sends the content. s. send (bytesSent,
, buffer, Len) {If (errno = ewouldblock){Return 0; // indicates that no data is read.} Else return-1; // indicates that the read fails.} Else return nread; read Data Length
Write operation
For write operations, the principle is similar. When the non-blocking socket has no space for sending the buffer, it will directly return the error code ewouldblock,Indicates that there is no space for writing data. If the error number is another value, it indicates
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.