红联Linux门户
Linux帮助

socket编程 recv() 函数

发布时间:2007-05-15 14:14:25来源:红联作者:xiaowjr
#include
#include
#include
#include
#include
#include
#include
#include
#include
main()
{ struct sockaddr_in local,server;
int soc,soc_temp,len_server;
int len=sizeof(struct sockaddr_in);
char in[9999],*out="hello word",*err;
printf("socket now the len is %d\n",len);
if((soc=socket(AF_INET,SOCK_STREAM,0))==-1)
{
perror("socket error!");
exit(0);
}
printf(" soc is %d \n",soc);
local.sin_family=AF_INET; /* 21 */
local.sin_port=htons(3777);
local.sin_addr.s_addr=inet_addr("127.0.0.1");
bzero(&local,len);
if((connect(soc,(struct sockaddr*)&local,len))==-1)
{
perror("\n connect error ");
exit(0);
}
else printf("\n connectsucess \n");
printf("begian to send \n");
if(recv(soc,in,999,0)==-1)
{
perror("errno");
exit(0);
}
else printf(" read success \n");
close(soc);
printf(" it's time to sleep");
}
~
结果出现如下结果:
socket now the len is 16
soc is 3

connectsucess
begian to send
errno: Transport endpoint is not connected
请问是什么问题?望大虾赐教!
文章评论

共有 2 条评论

  1. yarges 于 2010-02-03 14:08:10发表:

    你把发送端的代码贴出来看看

  2. jiangice 于 2007-05-20 22:14:10发表:

    怎么没有看到你启动TCP服务器啊?