|
-
January 29th, 2008, 06:49 AM
#1
receive data from specified IP address and Port number
Hi
I need help to receive data from Broadcast server. I have IP and Port number.
my system was connected broadcast server with port number : 1111
and with IP address : "124.12.125.2"
My task is to receive data from port
i write code like
#include<stdio.h>
#include<winsock.h>
void main()
{
WSADATA wsaData;
SOCKET SendSocket;
char SendBuf[215] ;
sockaddr_in RecvAddr;
int len =sizeof(RecvAddr);
int Port = 1111;
char ip[] = "124.12.125.2";
WSAStartup(MAKEWORD(2,2), &wsaData);
SendSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
RecvAddr.sin_family = AF_INET;
RecvAddr.sin_port = htons(Port);
RecvAddr.sin_addr.s_addr = inet_addr(ip);
while(1){
memset(SendBuf,' ' ,215) ;
if (recvfrom(SendSocket,SendBuf,sizeof( SendBuf),0,(struct sockaddr*)&RecvAddr,&len) != SOCKET_ERROR){
printf("rece from server:%s\n",SendBuf);
}
else
{
fprintf(stderr,"Client: recv() failed: error %d.\n", WSAGetLastError());
closesocket(SendSocket);
WSACleanup();
exit(0) ;
}
}
WSACleanup();
}
I am getting output as
Client: recv() faild: error 10022
what is this error ?
How can i read data from broadcast ?
please help me
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|