linux下tcp服务器源码示例
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
struct _NSS_HEADER
{
unsigned short ProtocolVersion; /* 协议版本信息 */
unsigned short MsgType; /* 消息类型 */
unsigned short TransactionNo; /* 传输编号 */
unsigned short PacketLength; /* 数据包长度,包括Header */
}NSS_HEADER;
void str_echo(int sockfd)
{
ssize_t readLen;
ssize_t writeLen;
char buf[8];
while ( true )
{
readLen = read(sockfd, buf, 8);
if (readLen < 0 && errno == EINTR)
{
continue;
}
else if ( readLen <= 0 )
{
perror( "read:");
return ;
}
printf( "recv data successed. data len: %d\n", readLen );
int nWriteLen = 0;
while ( true )
{
writeLen == write(sockfd, &buf[nWriteLen], readLen-nWriteLen);
if (writeLen < 0 && errno == EINTR)
{
continue;
}
else if ( writeLen < 0 )
{
perror ( "write:" );
return;
}
nWriteLen += writeLen;
// 已写完,直接返回
if (nWriteLen >= readLen )
{
break;
}
}
printf( "send data successed. data len: %d\n", readLen );
}
}
int main(int argc, char **argv)
{
printf( "server ip: %s\n", argv[1] );
printf( "server port: %s\n", argv[2] );
printf( "\nservice starting ... \n\n" );
int listenfd, connfd;
pid_t childpid;
socklen_t clilen;
struct sockadd
相关文档:
1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI) 就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......
Windows系统其实和Linux系统有相似的地方,Windows系统文件、目录的属性有只读、隐藏,而Linux也一样。 Linux中,每一个文件都具有特定的属性。主要包括文件类型和文件权限两个方面。可以分为5种不同的类型:普通文件、目录文件、链接文件、设备文件和管道文件。 所谓的文件权限,是指对文件的访问权限,包括对 ......
会员下载:
http://vipdown.3800hk.com/jiaocheng/linux/linux/@LinkGate@12403487266409x1196776239x12403488007143-5740071909166dc778c8b9deb5c6b4cc@LK@/01.rar
http://vipdown.3800hk.com/jiaocheng/linux/linux/@LinkGate@12403487266409x1196776239x12403488007143-177072d80fd416c4134c7 ......
PDF格式文件中的文本是可以导出来再修改的。
同样,PDF里面的插图也是可以提取出来的。
PDF转纯文本:
pdftotext -enc GBK godson2e-data.Sheet.pdf text.GBK.txt
-enc (encoding)
要参照/etc/xpdf/xpdfrc 里面提到的编码格式。对于中文,用GBK
就可以了。
提取插图:
pdfimages godson2e-data.Sheet.pdf img
该 ......
linux shell pwd 显示当前路径
假若有test.cpp
g++ test.cpp -o test
./test
想在test中找到当前执行程序所在的路径
可以再test.cpp中使用readlink函数
具体见如下实例:
#include<iostream>
#include<unistd.h>
#include<dirent.h>
#include<string.h>
#include<string>
using ......