|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2010-11-4 23:58:44
|
显示全部楼层
对了,这里是连接的示例。使用的操作系统是rt-thread
void client_thread_entry(void *parameter)
{
int sock;
int i = 0;
struct sockaddr_in srv_addr;
sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock == -1)
{
DEBUG_OUT("-->socket fail\n");
while(1) thread_delay(100);
}
DEBUG_OUT("-->socket OK\n");
DNS_resolve("ancheel.oicp.net", &(srv_addr.sin_addr));
srv_addr.sin_family = AF_INET;
srv_addr.sin_port = 8500;
{
char _tmp[20];
ipaddr2str(srv_addr.sin_addr.s_addr, _tmp);
DEBUG_OUT("-->sever ip: %s\n", _tmp);
}
while(1)
{
if(connect(sock, (struct sockaddr *) &srv_addr, 0) == -1)
{
DEBUG_OUT("-->connect ancheel.oicp.net fail\n");
while(1) thread_delay(100);
}
DEBUG_OUT("-->connect ancheel.oicp.net OK\n");
while(1)
{
DEBUG_OUT("-->send heart\n");
send(sock, NULL, 0, 0);
if(++i == 10)
{
i = 0;
break;
}
thread_delay(100*60);
}
closesocket(sock);
thread_delay(100*60);
}
} |
|