问题描述
现在,我正在尝试制作有关在线视频点播的软件,使用p2p解决网络问题.
以下是错误&我找不到路...
PS:好像有点乱了...原谅我...
Now I''m trying to make a sofeware about online video on demand,use p2p to solve network question.
The following is an error & i can''t find the way...
PS: it''s seems like a litter longer... forgive me...
int Command() //get the command
{
char key[256],temp[256];
int i,j,result;
char *command[6]={"connect","play","pause","stop","quit","?"};
char parameter[256];
printf("please input command................\n");
while(1)
{
memset(key,0,256);
memset(temp,0,256);
memset(parameter,0,256);
int flag=0;
printf("%s>>",strHostName); //show the command symbol
gets(temp);
j=0; //remove the excess space
for(i=0;i<strlen(temp);i++)>
{
if(temp[i+1]!='\0')
{
if(temp[i]==' '&&temp[i+1]==' ')i++;
else{key[j]=temp[i];j++;}
}
else
{
if(temp[i]==' '){key[j]='\0';break;}
else{key[j]=temp[i];j++;key[j]='\0';}
}
}
key[j+1]='\0';
i=strcspn(key," ");
key[i]='\0';
i++;j=0;
while(key[i]!='\0')
{
parameter[j]=key[i];
i++;j++;
}
parameter[j]='\0';
for(i=0;i<13;i++) //compare with the original command String
if(strcmp(key,command[i])==0)
{
flag=1;
break;
}
if(flag==0)
{
printf("%s>>",strHostName);
cout<<"bad command!"<<endl;
}
else
{
switch(i)
{
case 0:
result=Connect(parameter);
break;
case 1:
result=Play(parameter);
break;
case 2:
Pause();
break;
case 3:
Stop();
break;
case 4:
Quit();
exit(0);
case 5:
for(i=0;i<6;i++)
{
printf(command[i]);
printf("\n");
}
break;
}
}
switch(result)
{
case 0:
break;
case 1:
printf("%s>>",strUserName);
cout<<"parameters are not enough!"<<endl;
case 2:
printf("%s>>",strUserName);
cout<<"parameters are more!"<<endl;
}
}
}
int Connect(LPSTR parameter)
{
int i,j,k,len=strlen(parameter);
char temp[10];
//////////////////////////////////////////////////parameter/////////////////////////////////////////
if(!strlen(parameter))
return 1; //no parameter
k=strcspn(parameter," ");
parameter[k]=5;
i=0;j=0;
while(parameter[i]!=5)
{
sIP[j]=parameter[i];
i++;j++;
}
sIP[j]='\0';
k=strcspn(parameter," ");
if(k==len)
return 1; // lack parameter
parameter[k]=5;
i++;j=0;
while(parameter[i]!=5)
{
strUserName[j]=parameter[i];
i++;j++;
}
strUserName[j]='\0';
k=strcspn(parameter," ");
if(k==len)
return 1;
parameter[k]=5;
i++;j=0;
while(parameter[i]!=5)
{
strPassWord[j]=parameter[i];
i++;j++;
}
strPassWord[j]='\0';
k=strcspn(parameter," ");
if(k<len)>
return 2; //excess parameter
i++;j=0;
while(parameter[i]!='\0')
{
temp[j]=parameter[i];
i++;j++;
}
temp[j]='\0';
Port=atoi(temp);
然后打开clients.exe,无论用什么词,答案始终是参数不够用".
我对此一无所知...希望有人救我,除非我的上帝.
将标签更改为C,因为其中没有C ++.
Then open clients.exe,no matter what words,the answer always be"parameters are not enought¶meters are more "
I have no idea about it...hope someone to save me unless my god..
Changed tags to C as there''s no C++ in there
推荐答案
switch(result)
{
case 0:
break;
case 1:
printf("%s>>",strUserName);
cout<<"parameters are not enough!"<<endl;
break; //if this isn't here case 2 will also run!
case 2:
printf("%s>>",strUserName);
cout<<"parameters are more!"<<endl;
break; //you don't need this one, but it will prevent problems if you add more cases and forget to add it then
}
这就是为什么您同时收到两条消息的原因.两者都告诉我,您总是遇到情况1(情况0将不显示任何内容,情况2将仅显示最后一条消息).因此,调试程序并找出正在击中哪个"return 1",然后从那里开始工作!
So that''s why you get both messages. Getting both tells me that you are always hitting case 1 (case 0 would print nothing, and case 2 would only print the last message). So debug the program and figure out which "return 1" is being hit, and work from there!
这篇关于关于p2p客户端代码的一些知识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!