[JSBSim]基于winsocket2的TCP\UDP使用例子
TCP部分:
参考:http://blog.csdn.net/sbfksmq/article/details/50808863
另附:linux下的tcp/udp参考:https://www.cnblogs.com/lyggqm/p/9111010.html
TCP_SEVER:
// winsocketTCPServer.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h" //服务器
#include<iostream>
#include<WinSock2.h> // socket 所需要的头文件
#pragma comment(lib,"WS2_32.lib")// link socket 库
#define PORT 9999
#define BUFLEN 1024
using namespace std;
int main()
{
WSADATA wsaData;
// 1 启动并初始化winsock(WSAStarup)
if (WSAStartup(MAKEWORD(, ), &wsaData))//成功返回0
{
return FALSE;
}
//2 创建套接字(socket)
SOCKET sServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (INVALID_SOCKET == sServer)
{
WSACleanup();
return FALSE;
}
//3 准备通信地址
SOCKADDR_IN addrServer;
addrServer.sin_family = AF_INET;
addrServer.sin_port = htons(PORT);
addrServer.sin_addr.s_addr = INADDR_ANY;//任意可用地址
//4 绑定地址与socket(bind)
if (SOCKET_ERROR == bind(sServer, (const sockaddr*)&addrServer, sizeof(SOCKADDR_IN)))
{
closesocket(sServer);
WSACleanup(); return FALSE;
}
//5 监听 (listen)
if (SOCKET_ERROR == listen(sServer, SOMAXCONN))
{
closesocket(sServer);
WSACleanup();
}
// 6 等待客户端连接(accpet)
sockaddr_in addrClient;
int addrClientLen = sizeof(addrClient);
cout << "服务器启动成功,等待客户端连接中。。。。" << endl;
SOCKET sClient = accept(sServer, (sockaddr *)&addrClient, &addrClientLen);
if (INVALID_SOCKET == sClient)
{
cout << WSAGetLastError() << endl;
closesocket(sServer);
closesocket(sClient);
WSACleanup();
return FALSE;
}
//7 接收数据(recv)
char recvBuf[BUFLEN];
ZeroMemory(recvBuf, sizeof(recvBuf));
if (SOCKET_ERROR == recv(sClient, recvBuf, sizeof(recvBuf), ))
{
closesocket(sServer);
closesocket(sClient);
WSACleanup();
return FALSE;
}
cout << "客户端(" << inet_ntoa(addrClient.sin_addr) << ":" << addrClient.sin_port << "):" << recvBuf << endl;
//8 发送数据
char sendBuf[BUFLEN] = "你好客户端!";
if (SOCKET_ERROR == send(sClient, sendBuf, sizeof(sendBuf), ))
{
closesocket(sServer);
closesocket(sClient);
WSACleanup();
return FALSE;
}
system("pause");
system("pause");
return TRUE;
}
/*
注:1:MAKEWORD把参数组成一个WORD(双字节)类型数据并返回这个WORD类型数值,高位代表(修订本)号,低位字节指定主版本号(其代表)
2:socket(AF_INET,//The Internet Protocol version 4 (IPv4) address family
SOCK_STREAM,//, two-way,This socket type uses the Transmission Control Protocol (TCP) for the Internet address family (AF_INET or AF_INET6).
IPPROTO_TCP//The Transmission Control Protocol (TCP). This is a possible value when the af parameter is AF_INET or AF_INET6 and the type parameter is SOCK_STREAM.
)
*/
TCP_CLIENT:
// winsocketTCPClient.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h" //客户端
#include<iostream>
#include<WinSock2.h>
#pragma comment(lib,"WS2_32.lib")
using namespace std;
#define BUFLEN 1024
#define PORT 9999
void getIP(char*szHostaddress);
int main()
{ WSADATA wsaData;
// 1 启动并初始化winsock(WSAStarup)
if (WSAStartup(MAKEWORD(, ), &wsaData))//成功返回0
{
return FALSE;
}
//2 创建套接字(socket)
SOCKET sHost = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (INVALID_SOCKET == sHost)
{
closesocket(sHost);
WSACleanup();
return FALSE;
}
//3 准备通信地址
char szHostaddress[];
getIP(szHostaddress);
SOCKADDR_IN addrServer;
addrServer.sin_family = AF_INET;
addrServer.sin_port = htons(PORT);
addrServer.sin_addr.s_addr = inet_addr(szHostaddress);
//4 连接服务器(connect)
if (SOCKET_ERROR == connect(sHost, (const sockaddr*)&addrServer, sizeof(addrServer)))
{
closesocket(sHost);
WSACleanup();
return FALSE;
}
//5 发送数据 (send)
char sendBuf[BUFLEN] = "你好服务器!";
if (SOCKET_ERROR == send(sHost, sendBuf, sizeof(sendBuf), ))
{
closesocket(sHost);
WSACleanup();
return FALSE;
}
cout << "客户端发送消息成功!" << endl;
//7 接收数据(recv)
char recvBuf[BUFLEN];
ZeroMemory(recvBuf, sizeof(recvBuf));
if (SOCKET_ERROR == recv(sHost, recvBuf, sizeof(recvBuf), ))
{
closesocket(sHost);
WSACleanup();
return FALSE;
}
cout << "服务器发来的消息:" << recvBuf << endl;
system("pause");
}
void getIP(char*szHostaddress) {
char szHostname[];
if (gethostname(szHostname, sizeof(szHostname)) != SOCKET_ERROR)//先得到主机名
{
HOSTENT *pHostEnt = gethostbyname(szHostname);//通过名字拿到地址
if (pHostEnt != NULL)
{
sprintf(szHostaddress, "%d.%d.%d.%d",
(pHostEnt->h_addr_list[][] & 0x00ff),
(pHostEnt->h_addr_list[][] & 0x00ff),
(pHostEnt->h_addr_list[][] & 0x00ff),
(pHostEnt->h_addr_list[][] & 0x00ff));
}
}
else
return;
}
UDP部分:
参考:http://blog.csdn.net/sbfksmq/article/details/51046439
UDP_SERVER:
// 服务端
// UDP.cpp : 定义控制台应用程序的入口点。
//1 为UDP通信,单例模式
//2 一些socket函数不兼容 预处理器定义里添加如下的宏
//_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE;
//3 UDP为非面向连接方式不需要listen 与accept
#include"stdafx.h"
#include"afxwin.h"
#include"WinSock2.h"
#include<iostream>
#include <ws2tcpip.h>
#pragma comment(lib,"WS2_32.lib")
using namespace std;
//日志 可以不看
bool WriteErrorLogFile(CString csData)// errorlog
{
char buff[];
CString ErrorLog;
GetModuleFileName(NULL, (LPWSTR)buff, sizeof(buff));
cout << buff << endl;
ErrorLog = CString(buff);
ErrorLog += ErrorLog.Left(ErrorLog.ReverseFind('\\')) + "\\ErrorLog"; CString stemp;
CString sPathName;
SYSTEMTIME sys_time;
GetLocalTime(&sys_time); sPathName = ErrorLog; stemp.Format(L"%d%d%d", sys_time.wYear, sys_time.wMonth, sys_time.wDay);
sPathName += "\\" + stemp; CreateDirectory(sPathName, NULL); CStdioFile f;
if (!f.Open(sPathName, CStdioFile::modeCreate | CStdioFile::modeNoTruncate | CStdioFile::modeWrite | CStdioFile::typeText))
{
return false;
}
f.SeekToEnd();
stemp.Format(L"%02d:%02d:%02d:%s\n", sys_time.wHour, sys_time.wMinute, sys_time.wSecond, csData);
f.WriteString(stemp);
f.Flush();
f.Close();
return true;
}
class UDPSERVER
{//私有
UDPSERVER(char *ip, char*port) :m_IP(ip), m_Port(port)
{
m_srvSocket = INVALID_SOCKET;
//init
// Init();
}
UDPSERVER(UDPSERVER const &that)
{ }
public:
static UDPSERVER *Instance(char*ip,char*port)
{
if (!_instance)
{
_instance = new UDPSERVER(ip, port);
}
return _instance;
}
static bool Init()
{
WSADATA wsaData;
try {
if (WSAStartup(0X202, &wsaData))//If successful, the WSAStartup function returns zero
{
int err = WSAGetLastError(); WSACleanup();
return true;
}
}
catch (...)
{
cout << "WSAStartup error code:" << WSAGetLastError() << endl;
return false;
}
return true;
}
static bool GetLocalIp(char *szIP)// 获取IP
{
char szHostName[];
ZeroMemory(szHostName, sizeof(szHostName));
if (gethostname(szHostName, sizeof(szHostName))== )//gethostname 函数要在WSAStartup后进行调用。。。
{
// cout << "szHostName = " <<szHostName<< endl;
HOSTENT*pHostEnt = gethostbyname(szHostName);
if (pHostEnt)
{
sprintf(szIP, "%d.%d.%d.%d", (pHostEnt->h_addr_list[][] & 0xff),
(pHostEnt->h_addr_list[][] & 0xff),
(pHostEnt->h_addr_list[][] & 0xff),
(pHostEnt->h_addr_list[][] & 0xff));
//cout<<szIP<<endl;
return true;
}
}
else
{
cout << "gethostname error code:" << WSAGetLastError()<<endl;
return false;
}
return true;
}
bool StartServer()
{ // create socket
m_srvSocket = socket(AF_INET, SOCK_DGRAM, );
if (INVALID_SOCKET == m_srvSocket)
{
WSACleanup();
char errBuf[];
WriteErrorLogFile(CString(itoa(WSAGetLastError(), errBuf, sizeof(errBuf))));
return false;
}
// address pAddrServer.sin_family = AF_INET;
pAddrServer.sin_port = htons(atoi(m_Port));
pAddrServer.sin_addr.s_addr = inet_addr(m_IP);//or INADDR_ANY:接收任意IP发来的数据或指定一个IP发送数据
//bind
if (bind(m_srvSocket, (const sockaddr*)&pAddrServer, sizeof(SOCKADDR_IN)))
{
WSACleanup();
closesocket(m_srvSocket);
char errBuf[];
WriteErrorLogFile(CString(itoa(WSAGetLastError(), errBuf, sizeof(errBuf))));
return false;
}
//jUDP no need to listen or accept
return true;
}
void RcvData(char*buff = NULL)
{
int nSrvAddrLen = sizeof(SOCKADDR);
char bufMessage[];
ZeroMemory(bufMessage, sizeof(bufMessage));
int nRetRcv = recvfrom(m_srvSocket, bufMessage, sizeof(bufMessage), , (sockaddr*)&pAddrServer, (int *)
&nSrvAddrLen);
/*recv,send,(TCP)从一个已连接的socket接收或发送数据
sendto,recvfrom(UDP/TCP):从一个已连接或未连接的socket接收或发送数据
当你对于数据报socket调用了connect()函数时,你也可以利用send()和recv()进行数据传输,
但该socket仍然是数据报socket,并且利用传输层的UDP服务。但在发送或接收数据报时,内核会自动为之加上目地和源地址信息。*/
//不管是recv还是recvfrom,都有两种模式,阻塞和非阻塞,可以通过ioctl函数来设置 if ( == nRetRcv)
{
WSACleanup();
closesocket(m_srvSocket);
char errBuf[];
WriteErrorLogFile(CString(itoa(WSAGetLastError(), errBuf, sizeof(errBuf))));
}
cout << "the client:"<<inet_ntoa(pAddrServer.sin_addr)<<" say:" << bufMessage << endl;
}
void SentData(char*buff=NULL)
{
// sendto
SOCKADDR_IN clientAddr;
clientAddr.sin_family = AF_INET;
clientAddr.sin_port = htons((short));//发送到的端口
clientAddr.sin_addr.s_addr = inet_addr(m_IP); int nRetSent = sendto(m_srvSocket,"hello client",sizeof("hello client"),, (SOCKADDR*)&clientAddr, sizeof(clientAddr));
if ( == nRetSent)
{
WSACleanup();
closesocket(m_srvSocket);
char errBuf[];
WriteErrorLogFile(CString(itoa(WSAGetLastError(), errBuf, sizeof(errBuf))));
}
}
private:
char *m_IP;
char *m_Port;
SOCKET m_srvSocket;
SOCKADDR_IN pAddrServer ;
static UDPSERVER* _instance;
};
UDPSERVER*UDPSERVER::_instance = NULL;
int main(int argc,char*argv[])
{
char szIP[] = {};
UDPSERVER::Init();
if (false != UDPSERVER::GetLocalIp(szIP))
{
UDPSERVER* pUdpServer = UDPSERVER::Instance(szIP, "");
if (pUdpServer->StartServer())
{
while ()
{
pUdpServer->RcvData();
pUdpServer->SentData();
}
}
else
{
delete pUdpServer;
pUdpServer = NULL;
}
}
system("pause");
return ;
}
UDP_CLIENT:
//客户端
#include "stdafx.h"
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include<iostream>
#pragma comment (lib, "Ws2_32.lib")
using namespace std;
int main(int argc, char **argv)
{
//1 初始化
WSADATA wsaData;
SOCKET sServer;
WSAStartup(0x202, &wsaData);
//2 创建绑定socket
sServer = socket(AF_INET, SOCK_DGRAM, );
SOCKADDR_IN srvAddr;
srvAddr.sin_family = AF_INET;
srvAddr.sin_port = htons();
srvAddr.sin_addr.s_addr = inet_addr("172.168.28.201");
bind(sServer, (const sockaddr*)&srvAddr, sizeof(srvAddr));
//3 准备数据传输目的地的地址与数据
int nSrvAddrLen = sizeof(srvAddr);
char szSendBuff[];
ZeroMemory(szSendBuff, sizeof(szSendBuff));
memcpy(szSendBuff, "hello server", sizeof("hello server"));
SOCKADDR_IN cltAddr;
cltAddr.sin_family = AF_INET;
cltAddr.sin_port = htons();// 发送到哪个端口 htons主机字节顺序转变成网络字节顺序
cltAddr.sin_addr.s_addr = inet_addr("172.168.28.201");//inet_addr 字符串转换为32位二进制网络字节序的IPV4地址
int nCltAddrLen = sizeof(cltAddr);
// 发送
sendto(sServer, szSendBuff, sizeof(szSendBuff), , (const sockaddr*)&cltAddr, nCltAddrLen);
// 接收
memset(szSendBuff, , sizeof(szSendBuff));
recvfrom(sServer, szSendBuff, sizeof(szSendBuff), , ( sockaddr*)&srvAddr, &nSrvAddrLen); /*inet_pton inetntop 可以在将IP地址在“点分十进制”和“网络二进制结构”之间转换。而且,这2个函数能够处理ipv4和ipv6。算是比较新的函数*/
struct protoent *pe = getprotobyname("udp");
//getpeername(sServer, (sockaddr*)&srvAddr, &nSrvAddrLen);
cout << "the client receive the message: " << endl;
cout << "/* the server ip:" << inet_ntoa(srvAddr.sin_addr) << endl;//inet_ntoa 将网络地址转换成“.”点隔的字符串格式
cout << " the server port is " <<ntohs(srvAddr.sin_port) << endl;//htons
cout << " the server protocol:" << pe->p_name << endl;
cout << " the server protocal num is " << pe->p_proto << endl;
cout << " the server message is : "<< szSendBuff << " */ " << endl;
system("pause");
return ;
}
SELECT部分:
参考:http://blog.csdn.net/sbfksmq/article/details/51051585
SELECT_SERVER:
// WinSelectModel.cpp : 定义控制台应用程序的入口点。
//
//server side ,select model
/*
Syntax:
int select(
_In_ int nfds,//Ignored. The nfds parameter is included only for compatibility with Berkeley sockets.
_Inout_ fd_set *readfds,//An optional pointer to a set of sockets to be checked for readability.
_Inout_ fd_set *writefds,//An optional pointer to a set of sockets to be checked for writability.
_Inout_ fd_set *exceptfds,//An optional pointer to a set of sockets to be checked for errors.
_In_ const struct timeval *timeout//The maximum time for select to wait, provided in the form of a TIMEVAL structure. Set the timeout parameter to null for blocking operations.
)
功能:简单的讲就是一个socket“复用器”(不必为第个客户建立新线程,但需要不断轮询fd_set检测,fd_set的大小固定64),它能够检测报告一个或多个socket状态 ,但不如WSAASyncSelct()那么细致,第次调用,select ()把一组socket作为输入参数,而且它是阻塞的(可设置),也就是说该函数能使你同时检测多个socket的状态,它需要通过返回值来带回执行结果
Return value:成功返回当前状态与设定状态相匹配的socket的总数,超时返回0(timeout参数),失败返回SOCKET_ERROR
remarks:它与BSD兼容 ,也可以使用WSAAsyncSelect() ,timeout非零则阻塞,零则不阻塞(但不要传NULL为无限阻塞)
应用:网络连接数不大的程序
与select配合使用的宏
FD_ZERO(*set) :对fd_set初始化
FD_SET(s, *set):添加指定s套接字至集合
FD_CLR(s, *set):删除指定s套接字至集合
FD_ISSET(s, *set):检查指定s套接字是否集合
FD_SETSIZE: 64
*/
#include "stdafx.h"
#include<iostream>
#include<WinSock2.h> // socket 所需要的头文件
#pragma comment(lib,"WS2_32.lib")// link socket 库
#define PORT 6666
#define BUFLEN 1024
using namespace std;
fd_set g_fdClientSocket;
//fd_set
DWORD WINAPI ThreadProc(LPVOID lpParameter);
int main()
{ DWORD dwThreadID;
sockaddr_in addrClient;
int addrClientLen = sizeof(addrClient);
SOCKET sServer = INVALID_SOCKET;
SOCKET sClient;
int nClientCount = ;
// 1 启动并初始化winsock(WSAStarup)
WSADATA wsaData;
if (WSAStartup(0x202, &wsaData))//成功返回0
{
return FALSE;
}
//2 创建套接字(socket)
sServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (INVALID_SOCKET == sServer)
{
WSACleanup();
return FALSE;
}
//3 准备通信地址
SOCKADDR_IN addrServer;
addrServer.sin_family = AF_INET;
addrServer.sin_port = htons(PORT);//服务器用于监听的端口号,客户端需要知道这个端口进行连接
addrServer.sin_addr.s_addr = INADDR_ANY;
//4 绑定地址与socket(bind)
if (SOCKET_ERROR == bind(sServer, (const sockaddr*)&addrServer, sizeof(SOCKADDR_IN)))
{
closesocket(sServer);
WSACleanup();
return FALSE;
}
//5 监听 (listen)
if (SOCKET_ERROR == listen(sServer, SOMAXCONN))
{
closesocket(sServer);
WSACleanup();
}
//6 线程利用select()处理可读的客户端
CreateThread(NULL, , ThreadProc, NULL, , &dwThreadID);
// 7 等待多个客户端连接(accpet)
while (nClientCount<FD_SETSIZE)
{
sClient= accept(sServer, (sockaddr *)&addrClient, &addrClientLen);
if (INVALID_SOCKET == sClient)
{
cout << WSAGetLastError() << endl;
//或根据错误码进行其他操作
closesocket(sServer);
closesocket(sClient);
WSACleanup();
return FALSE;
}
printf("Accepted client:%s:%d\n", inet_ntoa(addrClient.sin_addr), ntohs(addrClient.sin_port));
FD_SET(sClient,& g_fdClientSocket);
nClientCount++;
}
system("pause");
return TRUE;
}
// 只处理是可读状态的socket
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
fd_set fdRead;
fd_set fdWrite;
FD_ZERO(&fdRead);
FD_ZERO(&fdWrite); int nRet = ; char recvBuffer[] = {}; struct timeval stTimeOut = { , }; while (true)
{
fdRead = g_fdClientSocket;
fdWrite = g_fdClientSocket;
nRet = select(, &fdRead, &fdWrite, NULL, &stTimeOut);
if (SOCKET_ERROR != nRet)
{
for (int i = ; i < g_fdClientSocket.fd_count; i++)
{
if (FD_ISSET(g_fdClientSocket.fd_array[i], &fdRead))
{
memset(recvBuffer, , sizeof(recvBuffer));
SOCKADDR_IN stAddrTemp;
int nTempLen = sizeof(stAddrTemp);
nRet = recvfrom(g_fdClientSocket.fd_array[i], recvBuffer, sizeof(recvBuffer), , (sockaddr*)&stAddrTemp, &nTempLen);
if (SOCKET_ERROR == nRet)
{
closesocket(g_fdClientSocket.fd_array[i]);
FD_CLR(g_fdClientSocket.fd_array[i], &g_fdClientSocket);
}
else
{
cout << "the client(" << inet_ntoa(stAddrTemp.sin_addr) << ":" << ntohs(stAddrTemp.sin_port) << ") :" << recvBuffer << "(message size is " << nTempLen << ")" << endl;
}
}
if (FD_ISSET(g_fdClientSocket.fd_array[i], &fdWrite))
{
nRet = send(g_fdClientSocket.fd_array[i], "hello Client", sizeof("hello Client"), );
if (SOCKET_ERROR == nRet)
{
int nErrorNo = WSAGetLastError();
cout << "send error code is " << nErrorNo << endl;//10038 socket handle parameter did not reference a valid socket, or for select, a member of an fd_set was not valid.
closesocket(g_fdClientSocket.fd_array[i]);
FD_CLR(g_fdClientSocket.fd_array[i], &g_fdClientSocket);
}
else
{
continue;
}
}
}
}
}
}
SELECT_CLIENT:
// WinSelectClient.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include<WinSock2.h>
//客户端
#include<iostream>
#pragma comment(lib,"WS2_32.lib")
using namespace std;
#define BUFLEN 1024
#define PORT 6666
void getIP(char*szHostaddress);
void SendProc();
SOCKET sHost;
int main()
{
WSADATA wsaData;
// 1 启动并初始化winsock(WSAStarup)
if (WSAStartup(MAKEWORD(, ), &wsaData))//成功返回0
{
return FALSE;
}
//2 创建套接字(socket)
sHost = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (INVALID_SOCKET == sHost)
{
closesocket(sHost);
WSACleanup();
return FALSE;
}
//3 准备通信地址
char szHostaddress[];
getIP(szHostaddress);
SOCKADDR_IN addrServer;
addrServer.sin_family = AF_INET;
addrServer.sin_port = htons(PORT);
addrServer.sin_addr.s_addr = inet_addr(szHostaddress);
//4 连接服务器(connect)
if (SOCKET_ERROR == connect(sHost, (const sockaddr*)&addrServer, sizeof(addrServer)))//连接到指定的地址
{
closesocket(sHost);
WSACleanup();
return FALSE;
}
//5 发送数据 (send)
char sendBuf[BUFLEN] = "你好服务器!";
if (SOCKET_ERROR == send(sHost, sendBuf, sizeof(sendBuf), ))
{
closesocket(sHost);
WSACleanup();
return FALSE;
}
cout << "客户端发送消息成功!" << endl;
//7 接收数据(recv)
char recvBuf[BUFLEN];
ZeroMemory(recvBuf, sizeof(recvBuf));
if (SOCKET_ERROR == recv(sHost, recvBuf, sizeof(recvBuf), ))
{
closesocket(sHost);
WSACleanup();
return FALSE;
}
cout << "服务器发来的消息:" << recvBuf << endl;
while (true)
{
SendProc();
Sleep();
}
system("pause");
}
void SendProc(
)
{
char sendBuf[BUFLEN] = "你好服务器!";
if (SOCKET_ERROR == send(sHost, sendBuf, sizeof(sendBuf), ))
{
closesocket(sHost);
WSACleanup();
return ;
}
cout << "客户端发送消息成功!" << endl;
} void getIP(char*szHostaddress) {
char szHostname[];
if (gethostname(szHostname, sizeof(szHostname)) != SOCKET_ERROR)//先得到主机名
{
HOSTENT *pHostEnt = gethostbyname(szHostname);//通过名字拿到地址
if (pHostEnt != NULL)
{
sprintf(szHostaddress, "%d.%d.%d.%d",
(pHostEnt->h_addr_list[][] & 0x00ff),
(pHostEnt->h_addr_list[][] & 0x00ff),
(pHostEnt->h_addr_list[][] & 0x00ff),
(pHostEnt->h_addr_list[][] & 0x00ff));
}
}
else
return;
}
[JSBSim]基于winsocket2的TCP\UDP使用例子的更多相关文章
- 最简单的Tcp Udp的例子
//1.WinSock包含2个主要的版本,即WinSock1和WinSock2.前者需要包含头文件WinSock.h和库文件wsock32.lib,后者需要包含头文件WinSock2.h和库文件ws2 ...
- [原][JSBSim]基于qt代码实现:TCP|UDP与飞行模拟软件JSBSim的通信,现实模型飞行!
废话没有,上关键代码 头文件 #include <QUdpSocket> #include <qtcpsocket.h> #ifndef vrUDP #define vrUDP ...
- Nginx基于TCP/UDP端口的四层负载均衡(stream模块)配置梳理
通过我们会用Nginx的upstream做基于http/https端口的7层负载均衡,由于Nginx老版本不支持tcp协议,所以基于tcp/udp端口的四层负载均衡一般用LVS或Haproxy来做.至 ...
- Fixed-Length Frames 谈谈网络编程中应用层(基于TCP/UDP)的协议设计
http://blog.sina.com.cn/s/blog_48d4cf2d0101859x.html 谈谈网络编程中应用层(基于TCP/UDP)的协议设计 (2013-04-27 19:11:00 ...
- 基于tcp/udp的协议
使用TCP协议的常见端口主要有以下几种: (1) FTP:定义了文件传输协议,使用21端口.常说某某计算机开了FTP服务便是启动了文件传输服务.下载文件,上传主页,都要用到FTP服务. (2) Tel ...
- Kcptun 是一个非常简单和快速的,基于KCP 协议的UDP 隧道,它可以将TCP 流转换为KCP+UDP 流
本博客曾经发布了通过 Finalspeed 加速 Shadowsocks 的教程,大家普遍反映能达到一个非常不错的速度.Finalspeed 虽好,就是内存占用稍高,不适合服务器内存本来就小的用户:而 ...
- 开源基于asio的网络通信框架asio2,支持TCP,UDP,HTTP,RPC,SSL,跨平台,支持可靠UDP,支持TCP自动拆包,TCP数据报模式等
开源基于asio的网络通信框架asio2,支持TCP,UDP,HTTP,RPC,SSL,跨平台,支持可靠UDP,支持TCP自动拆包,TCP数据报模式等 C++开发网络通信程序时用asio是个不错的选择 ...
- 涨知识-VI 基于TCP/UDP的应用层协议
基于TCP/UDP的应用层协议: 基于TCP: Telnet(Teletype over the Network, 网络电传),通过一个终端(terminal)登陆到网络 FTP(File Trans ...
- nginx篇高级用法之基于TCP/UDP的四层调度
nginx 从1.9版本开始支持基于TCP/UDP的四层调度,在编译nginx时使用--with-stream开启该模块 支持TCP/UDP调度时,支持给所有的软件做调度器,例如:nfs smb ft ...
随机推荐
- 怎么在jquery里清空文本框的内容
$("input[name='test']").val("").focus(); // 将name=test的文本框清空并获得焦点,以便重新输入
- centos 专题-各种配置应有尽有
你想要的在这里都能得到解决: http://www.linuxidc.com/topicnews.aspx?tid=14
- discuz模板引擎
discuz是采用“编译型的模板”,就是指采用普通网页文件保存,在文件中插入需要动态显示数据的仿php的代码,最后进行编译成真正的php的文件保存为模板缓存文件,这个转换的过程就称为编译.在用户浏览页 ...
- only_full_group_by问题而引发的对group by的深入思考
问题背景 最近在项目中使用mysql的group by进行分组查询的场景比较多,其中一次遇到了一个问题,即在开发环境执行一个如下sql时是正确且可执行的, select a,b,max(c) from ...
- Java中如何优雅地删除List中的元素
在工作中的许多场景下,我们都会使用到List这个数据结构,那么同样的有很多场景下需要删除List中的某一个元素或某几个元素,那么我们该如何正确无误地删除List中的元素的,今天我来教大家三种方式. 前 ...
- 常用jquery记录
1.jquery easing jQuery Easing是一款比较老的jQuery插件,在很多网站都有应用,尤其是在一些页面滚动.幻灯片切换等场景应用比较多.它非常小巧,且有多种动画方案供选择,使用 ...
- 引入jQuery的src设置
1.引用在线jQuery 谷歌.微软.百度都有提供在线的jQuery引用.比如 <script src="http://code.jquery.com/jquery-latest.js ...
- Pointofix 1.7 Portable试用
Pointofix 1.7 Portable简体中文单文件便携版 软件大小:347K软件语言:简体中文软件类别:国外软件/桌面工具/教育教学运行环境:windows XP/Vista/Win7开 发 ...
- python 元组 序列上使用enumerate()函数
不能直接for n,x,y in enumerate(data)
- jQuery 是javascript的一个库(常用插件、处理器)
jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery就是javascript的一个库,把我 ...