This is both a java/c problem. I'm taking over a MC project that sends data from computer A to Computer B, but not the other way around (it physically can't). The MC comes through to Computer B, I can see this on WireShark & tcpdump, but I can't figure out how to troubleshoot exactly why my program won't read any MC packet. I took a project that I made a year ago and tried it, I have also used other people's projects online, but the only project that ever picked up a MC project at all was a java project, it grabbed 4 packets during 1 run, and 1 packet during another. When I use a sender/receiver on a regular network everything works fine. Does anyone have any ideas about what the problem could be?
Note: Yes this code is borrowed from another website, but I assure you I can do it on my own. I don't want to accidentally post proprietary info and end up getting fired.
It never goes past this line of code. I've quadruple checked the ports & ip addresses (so have a few other people). If we hook a separate computer (that makes this bidirectional) and use a different sender, everything works just fine.
Code:
recvfrom(fd,msgbuf,MSGBUFSIZE,0, (struct sockaddr *) &addr,&addrlen))
Here's a receiver that I'm using:
Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h> #include <string.h>
#include <stdio.h>
//////changed from actual
#define HELLO_PORT 12345
#define HELLO_GROUP "225.0.0.37"
#define MSGBUFSIZE 256
int main(int argc, char *argv[])
{
struct sockaddr_in addr;
int fd, nbytes,addrlen;
struct ip_mreq mreq;
char msgbuf[MSGBUFSIZE];
u_int yes=1;
if ((fd=socket(AF_INET,SOCK_DGRAM,0)) < 0)
{
perror("socket");
exit(1);
}
if (setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0)
{
perror("Reusing ADDR failed");
exit(1);
}
memset(&addr,0,sizeof(addr));
addr.sin_family=AF_INET;
addr.sin_addr.s_addr=htonl(INADDR_ANY);
addr.sin_port=htons(HELLO_PORT);
if (bind(fd,(struct sockaddr *) &addr,sizeof(addr)) < 0)
{
perror("bind");
exit(1);
}
mreq.imr_multiaddr.s_addr=inet_addr(HELLO_GROUP);
mreq.imr_interface.s_addr=htonl(INADDR_ANY//changed to listening interface ip address);
if (setsockopt(fd,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq)) < 0)
{
perror("setsockopt");
exit(1);
}
while (1)
{
addrlen=sizeof(addr);
if((nbytes=recvfrom(fd,msgbuf,MSGBUFSIZE,0, (struct sockaddr *) &addr,&addrlen)) < 0)
{
perror("recvfrom");
exit(1);
}
puts(msgbuf);
}
return 0;
}