bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

URGENT : UDP Broadcast don't seem to work ?


From: mickael guerin
Subject: URGENT : UDP Broadcast don't seem to work ?
Date: Mon, 28 Jul 2003 13:44:55 +0200 (CEST)

Hello !
I have a problem with class UDPBroadcast.
I create a server with an BroadcastAddress to send to.
There is no compile error, but the recever don't receive the message.
I don't know why.
Can anybody help me please ?
 
P.S: In my code, I can receive with unicast, but not with Broadcast. 
 
/* *************************************************************************** */
// TRAMSMITER

#include <cc++/socket.h>
#include <iostream>
#include <cstdlib>

#ifdef CCXX_NAMESPACES
using namespace std;
using namespace ost;
#endif

int main(int argc, char *argv[])
  int i = 69;
  int choix;
  cout << "Broadcast : 0\nUnicast : 1\nChoix : ";
  cin >>choix;
 
  BroadcastAddress ba = "192.168.1.255";
  InetAddress addr = "192.168.1.69";
  InetHostAddress ia = "192.168.1.69";

  UDPBroadcast *sock1= new UDPBroadcast(ba, 9999);
  UDPSocket *sock= new UDPSocket(addr, 9999);

  switch (choix){
    case 0 :
       sock1->setPeer(ba,8888);
       sock1->send(&i,4);
       break;
   case 1 :
       sock->setPeer(ia,8888);
       sock->send(&i,4);
  };
  cout << "message envoyé\n";
}

/* ******************************************************************* */
/ / RECEIVER

#include <cc++/socket.h>
#include <iostream>
#include <cstdlib>

#ifdef CCXX_NAMESPACES
using namespace std;
using namespace ost;
#endif

int main(int argc, char *argv[])
{
  int i ;
  InetAddress addr = "192.168.1.69";
  UDPSocket *sock = new UDPSocket(addr, 8888);
  sock->receive(&i,4);
  cout << "reçu " << i <<endl;
  cout << "fin\n";

}

 

 

 



Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Testez le nouveau Yahoo! Mail

Attachment: tcpstr1.cpp
Description: tcpstr1.cpp

Attachment: tcpstr2.cpp
Description: tcpstr2.cpp


reply via email to

[Prev in Thread] Current Thread [Next in Thread]