如线的定义:
struct Line{
int start_x,
int start_y,
int end_x,
int end_y
...
}
我是VC初学者,您能不能把关键代码回复一下.谢谢!
[此贴子已经被作者于2006-3-29 14:25:08编辑过]
//使用Socket的程序在使用Socket之前必须调用WSAStartup函数
int WSAStartup(
WORD wVersionRequested,
LPWSADATA lpWSAData
);
//应用程序在完成对请求的Socket库的使用后,要调用WSACleanup函数来解除与Socket库的绑定并且释放Socket库所占用的系统资源。
int WSACleanup (void);
//应用程序调用socket函数来创建一个能够进行网络通信的套接字
SOCKET socket(
int af,
int type,
int protocol
);
//当创建了一个Socket以后,套接字数据结构中有一个默认的IP地址和默认的端口号
int bind(
SOCKET s,
const struct sockaddr FAR *name,
int namelen
);
//closesocket函数用来关闭一个描述符为s套接字
int closesocket(
SOCKET s
);
//不论是客户还是服务器应用程序都用send函数来向TCP连接的另一端发送数据
int send(
SOCKET s,
const char FAR *buf,
int len,
int flags
);
//不论是客户还是服务器应用程序都用recv函数从TCP连接的另一端接收数据
int recv(
SOCKET s,
char FAR *buf,
int len,
int flags
);
*******因为时间有限以下只是个参考不是实际代码*******
#pragma pack(1)
struct Line{
int start_x;
int start_y;
int end_x;
int end_y;
//...
};
struct sockaddr_in sockAddr;
unsigned short Port = 1010;
int iRet = 0;
int iSocketId;
Line struLine;
bool bBroadcast = true;
iSocketId = 2222;
socket(AF_INET, SOCK_DGRAM, 0);
iSetSockRet = setsockopt(iSocketId,
SOL_SOCKET,
SO_BROADCAST,
(char *)&bBroadcast,
sizeof(BOOL));
sockAddr.sin_family = AF_INET;
sockAddr.sin_port = htons((unsigned short)Port);
sockAddr.sin_addr.s_addr = INADDR_ANY;
hRet = bind(iSocketId, (struct sockaddr *)&sockAddr, sizeof(struct sockaddr));
memset(&sockAddr, sizeof(struct sockaddr_in), sizeof(struct sockaddr_in));
sockAddr.sin_family = AF_INET;
sockAddr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
sockAddr.sin_port = htons(Port);
struLine.end_x = 1;
struLine.end_y = 2;
struLine.start_x = 3;
struLine.start_y = 4;
iRet = sendto(iSocketId,
(char *)&struLine,
sizeof(struLine),
0,
(struct sockaddr *)&sockAddr,
sizeof(sockAddr));
if (iRet < 0) {
cerr<<"Error";
}
sockclose(iSocketId);
[此贴子已经被作者于2006-3-29 20:05:14编辑过]