server端主函数
while(1) { int ret; Gate *clt=(Gate *)calloc(1, sizeof(Gate)); memset(Recv_Buf,0,sizeof(Recv_Buf)); ret=recv(sClinetSock,Recv_Buf,sizeof(Recv_Buf),0); printf("Recv_Buf Mesg:%s\n",Recv_Buf); ret=sizeof(Gate); printf("sizeof(Gate):%d\n",ret); sscanf(Recv_Buf,"%d%d%lf%lf%lf",&clt->tx_wave,&clt->gate_length,&clt->gate_length1,&clt->gate_length2,&clt->start_time); printf("Packet Report: \ntx_wave = %d\n gate_length = %d\n gate_length1 = %f\ngate_length2 = %f\nOPNET Time = %f\n", clt->tx_wave,clt->gate_length,clt->gate_length1,clt->gate_length2,clt->start_time); int message_size = sizeof(Gate); clt->tx_wave = clt->tx_wave + 2; memset(Send_Buf,0,sizeof(Send_Buf)); sprintf(Send_Buf,"%d %d %f %f %f",clt->tx_wave,clt-> gate_length,clt-> gate_length1,clt-> gate_length2,clt->start_time); printf("Send_Buf Mesg:%s\n",Send_Buf); send(sClinetSock,Send_Buf,sizeof(Send_Buf),0); free(clt); }
client端主函数
while(1) { Esa_Execute_Until(esa_handle, &status_1, time_val, exec_options, &time_reached, &num_events); recv(sClntSock,RSC_Buf,sizeof(RSC_Buf),0); printf("RSC_Buf Mesg:%s\n",RSC_Buf); Interface_Packet_Data *clt=(Interface_Packet_Data *)calloc(1, sizeof(Interface_Packet_Data)); sscanf(RSC_Buf,"%d%d%lf%lf%lf",&clt->tx_wave,&clt->gate_length,&clt->gate_length1,&clt->gate_length2,&clt->start_time); printf("收到的数据包为: \ntx_wave = %d\n gate_length = %d\n gate_length1 = %f\ngate_length2 = %f\nOPNET Time = %f\n", clt->tx_wave,clt->gate_length,clt->gate_length1,clt->gate_length2,clt->start_time); }
client端发送5个结构体给server。server更改结构体中yppe值后再返回给client,但是接收完后,程序好像处于奔溃,结果如下
一直在不停的接收最后一个包?问一下是怎么回事?
解决方案
5
server死循环里没有accept ?
5
假如你想认真搞网络编程的话买本unix网络编程看看吧。你这代码问题太多了,看了那本书基本上你就不会来问这种问题了。
10
看看服务器端分配的内存够不够
5
不知道有多少前人掉在TCP Socket
send(人多)send(病少)send(财富)
recv(人多病)recv(少财富)
陷阱里面啊!
http://bbs.csdn.net/topics/380167545
send(人多)send(病少)send(财富)
recv(人多病)recv(少财富)
陷阱里面啊!
http://bbs.csdn.net/topics/380167545