Discover linux socket programming by example pdf, include the articles, news, trends, analysis and practical advice about linux socket programming by example pdf on alibabacloud.com
implementing the output codevoidWrite_routine (intSockChar*buf) { while(1) {fgets (buf, Buf_size, stdin); if(!STRCMP (BUF,"q\n") || !STRCMP (BUF,"q\n") {shutdown (sock, SHUT_WR); return; } write (sock, buf, strlen (BUF)); }}at the same time the multi-process server also has shortcomings, each creation of a process represents a large number of operations and memory space consumption, mutual process data exchange is also very troublesome ... So how to fix it, the blog behind me may give an ans
); if(ch==1){//Send Messagescanf ("%s", BUF); Send (Ssock,"%$#@", Maxbuf,0);//tell the server to pass a stringSend (Ssock, buf, Maxbuf,0);//send a character to passrecv (Ssock, buf, maxbuf,msg_waitall);//Receive confirmation Informationputs (BUF); } Else if(ch==2){//Send Fileprintf ("input the filename:"); scanf ("%s", BUF); if(Freopen (BUF,"R", stdin)! =NULL) {Send (Ssock,"@#$%", Maxbuf,0);//tell the server to pass the fileSend (Ssock,buf,maxbuf,0);//Pass file name intCnt=0; whil
Non-blocking I/O includes non-blocking input operations, non-blocking output operations, non-blocking receiving foreign connections, non-blocking initiating outgoing connections. The functions included are: Read, Readv, recv, Recvfrom, Recvmsg, write, Writev, send, SendTo, sendmsg, accept.
There are three general ways to set the socket to non-blocking mode:
(1) When creating a socket, specify that the
The socket descriptor and the generic file descriptor do not differ in form, so how can I tell if a file descriptor is a socket descriptor? Here we will simply customize a function Issockettype for socket descriptor determination.#include #include #include #include #include #include intIssockettype (intFD) {structStat St;intErr = Fstat (fd, st);//Get the status o
network programming in Linux is implemented through sockets (sockets).There are three types of sockets: Streaming sockets (SOCK_STREAM) streaming sockets can provide a reliable, connection-oriented traffic flow that uses the TCP protocol. TCP guarantees the correctness and sequencing of data transmission. Datagram Sockets (SOCK_DGRAM) datagram sockets define a non-connected service that transmits data throu
("Listen failed! Error message:%s\n", Strerror (errno)); GotoEND; } intclient_st=0;//client-side socket structSockaddr_in clientaddr;//IP address of client side Charbuf[1024x768]={0}; intI=0; while(i1) {memset (AMP;CLIENTADDR,0,sizeof(CLIENTADDR)); socklen_t Len=0;//maximum number of bytes representing the client address /*Accept will block the current thread until a client connects, and the Accept () function returns the
Nbsp; the network communication program in Linux must deal with a structure, which is socketaddress. For example, functions such as bind and connect must use the socketaddress structure. To understand the socketaddress, we must understand that in linux, different socketdomains are defined as a common
The network communication program in
Note:
These two programs should be run on the same machine. You need to create the/home/rangaofei/c_test/directory in advance.
This afternoon I learned about socket communication programming, read a book, and find an online explanation. Although it is still dizzy, the small experiment is still successful, and I plan to study it further tomorrow.
Two simple small programs, client. C and server. C, are compi
Three Linux socket addresses
Common socket address of sockaddr
typedef unsigned short sa_family_t;struct sockaddr { sa_family_t sa_family; /* address family, AF_xxx */ char sa_data[14]; /* 14 bytes of protocol address */}
Socket address of sockaddr_in Internet
/* Str
Note: Only when epoll et (edge trigger) mode is used, you need to check whether the data has been read. When the select or epoll mode is used, you do not have to worry about whether the data has been read. If select/epoll detects that the data is readable, it is OK.
There are two methods:
1. For TCP, call the Recv method. Based on the return value of the Recv method, if the returned value is smaller than the size of the Recv buffer we specify, all data has been received. In
I was just beginning to touch the Linux socket programming, while the edge of the understanding of UDP socket programming, my question is that the server does not specify the IP address, the client's destination IP address is 127.0.0.1, so you can communicate? Is it not poss
Linux-non-blocking socket programming to handle EAGAIN errors-Linux general technology-Linux programming and kernel information, the following is a detailed description. Resource temporarily unavailable often occurs when a non-blo
The network communication program in Linux must deal with a structure, which is socket address. For example, functions such as bind and connect must use the socket address structure. We need to understand the socket address. In fact, in
The example program described in this paper is a socket network programming based on Linux platform, which realizes the file transfer function. This example is a socket network File transfer program based on the TCP stream protoco
Preface
This section describes how to use basic Linux/Unix functions to compile a complete server and client example that can be run on Linux (UBUNTU) and Unix (FreeBSD, the functions of the client and server are as follows:
The client reads a row from the standard input and sends it to the server.
The server reads a row from the network and then outputs th
/linux_programming/UNP/socket $./echoser_selectRecv connect IP = 127.0.0.1 Port = 54010FdsgfgdGfedgClient close
...........................
Simba @ Ubuntu :~ /Documents/code/linux_programming/UNP/socket $./echocli_select_shutdownLocal IP = Wagner. 0.0.1 Port = 54010FdsgfgdGfedgFdsgfgdGfedgServer connect close
If we change the shutdown in the client program to close, when the server sends data to the client
the data in the buffer.* Flags: Call way flag bit.* To: (optional) pointer to the address of the destination socket interface.* The length of the address referred to by tolen:to.*/SendTo (Socket_descriptor,buf,sizeof (BUF), 0, (struct sockaddr *) address,sizeof (address));}sprintf (buf, "stop\n");SendTo (Socket_descriptor,buf,sizeof (BUF), 0, (struct sockaddr *) address,sizeof (address));//Send Stop commandClose (Socket_descriptor);printf ("Messages
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.