Dear Mr,
I wrote one sample socket in linux, it broadcast an character to all the machines in my subnet.
I set socket options in udp to broadcast then sendto() the client, but I couldn't receive any thing in client.
I checked my program with several programs, it's same.but I can't receive from broadcast.
What should I do ?
Thanks for you incoming helps.
5 12622 sicarie 4,677
Recognized Expert Moderator Specialist
What did you write your program in?
Can you ping the machines from the computer your program is running on?
What programs did you "check yours against" and how did you check it?
Are you aware of the Networking definition of 'broadcast' and how that's different depending on your situation?
What did you write your program in?
Can you ping the machines from the computer your program is running on?
What programs did you "check yours against" and how did you check it?
Are you aware of the Networking definition of 'broadcast' and how that's different depending on your situation?
Dear Sicarie,
This is my program on both server and client side , please check and tell me more about Network definition od broad cast and different depending on my situation.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>Server Side>>>>>>>>>>>>>>>>>>> -
#include <stdio.h>
-
#include <sys/socket.h>
-
#include <arpa/inet.h>
-
#include <stdlib.h>
-
#include <string.h>
-
#include <unistd.h>
-
#include <netinet/in.h>
-
-
#define BUFFSIZE 255
-
void Die(char *mess) { perror(mess); exit(1); }
-
-
int main(int argc, char *argv[]) {
-
int sock;
-
struct sockaddr_in echoserver;
-
struct sockaddr_in echoclient;
-
char buffer[BUFFSIZE];
-
unsigned int echolen, clientlen;
-
int received = 0;
-
-
if (argc != 4) {
-
fprintf(stderr, "USAGE: %s <server_ip> <word> <port>\n", argv[0]);
-
exit(1);
-
}
-
/* Create the UDP socket */
-
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
-
Die("Failed to create socket");
-
}
-
/* Construct the server sockaddr_in structure */
-
memset(&echoserver, 0, sizeof(echoserver)); /* Clear struct */
-
echoserver.sin_family = AF_INET; /* Internet/IP */
-
echoserver.sin_addr.s_addr = inet_addr(argv[1]); /* IP address */
-
echoserver.sin_port = htons(atoi(argv[3])); /* server port */
-
-
/*Set socket option to broadcast*/
-
int opt = 1;
-
setsockopt(sock(), SOL_SOCKET, SO_BROADCAST, &opt, sizeof(int));
-
-
/* Send the word to the server */
-
echolen = strlen(argv[2]);
-
if (sendto(sock, argv[2], echolen, 0,
-
(struct sockaddr *) &echoserver,
-
sizeof(echoserver)) != echolen) {
-
Die("Mismatch in number of sent bytes");
-
}
-
-
close(sock);
-
exit(0);
<<<<<<<<<<<<<<<<<<<<<in other side program >>>>>>>>>>>>>>>>> -
#include <stdio.h>
-
#include <sys/socket.h>
-
#include <arpa/inet.h>
-
#include <stdlib.h>
-
#include <string.h>
-
#include <unistd.h>
-
#include <netinet/in.h>
-
-
#define BUFFSIZE 255
-
void Die(char *mess) { perror(mess); exit(1); }
-
-
int main(int argc, char *argv[]) {
-
int sock;
-
struct sockaddr_in echoserver;
-
struct sockaddr_in echoclient;
-
char buffer[BUFFSIZE];
-
unsigned int echolen, clientlen, serverlen;
-
int received = 0;
-
-
if (argc != 2) {
-
fprintf(stderr, "USAGE: %s <port>\n", argv[0]);
-
exit(1);
-
}
-
/* Create the UDP socket */
-
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
-
Die("Failed to create socket");
-
}
-
/* Construct the server sockaddr_in structure */
-
memset(&echoserver, 0, sizeof(echoserver)); /* Clear struct */
-
echoserver.sin_family = AF_INET; /* Internet/IP */
-
echoserver.sin_addr.s_addr = htonl(INADDR_ANY); /* Any IP address */
-
echoserver.sin_port = htons(atoi(argv[1])); /* server port */
-
-
/* Bind the socket */
-
serverlen = sizeof(echoserver);
-
if (bind(sock, (struct sockaddr *) &echoserver, serverlen) < 0) {
-
Die("Failed to bind server socket");
-
}
-
-
/* Run until cancelled */
-
while (1) {
-
/* Receive a message from the client */
-
clientlen = sizeof(echoclient);
-
if ((received = recvfrom(sock, buffer, BUFFSIZE, 0,
-
(struct sockaddr *) &echoclient,
-
&clientlen)) < 0) {
-
Die("Failed to receive message");
-
}
-
fprintf(stderr,
-
"Client connected: %s\n", inet_ntoa(echoclient.sin_addr));
-
-
}
-
}
-
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>
Please check my mistake, thanks again for incoming helps,
I sniffed packets in other machines that connected to the network, packet received but my receive program work bad and can't receive the packets.
Please checking my receive program "in other side program".
Best Kings.
sicarie 4,677
Recognized Expert Moderator Specialist
I sniffed packets in other machines that connected to the network, packet received but my receive program work bad and can't receive the packets.
Please checking my receive program "in other side program".
Best Kings.
Not sure how many of the networking people here are coders, so since you know you are receiving the packet on the destination computer (but not processing it correctly) I'm going to shift this over to the C/C++ forum - hopefully get a few more ideas over there.
Thanks ,I hope receive any help about this.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Gordon Wetzstein |
last post by:
Hello everyone,
I have a problem with python sockets.
I broadcast a lot of pickled objects with socket. sendto(...), that works.
Ireceive them on the other site with socket.recvfrom(16384)
The...
|
by: Brad Tilley |
last post by:
I have a function that starts a socket server looping continuously
listening for connections. It works. Clients can connect to it and send
data.
The problem is this: I want to get the data that...
|
by: Austin |
last post by:
.........................
data = ....
self.broadcast_ip = 255.255.255.255
UDPSock.sendto(data,(self.broadcast_ip,36))
..........................
These codes run on Windows without errors...
|
by: Alexander Muylaert |
last post by:
Hi
I their a way I can interupt socket.Receive.
I want my multi-threader server to be able to handle requests as wel as
Broadcast messages. This broadcasting is done when the socket is not...
|
by: Justin Creasy |
last post by:
If this is the wrong group for this posting please let me know and I'll
move it.
I have an application that has an ArrayList of sockets to clients. For
standard one-to-one messages my...
|
by: rs |
last post by:
how I the client tell the server that the socket is closed? or this there an
even that informs the server that the clients socket is close?
Oh, I am using vb.net 2003
Thanks
|
by: Islamegy® |
last post by:
Hiiiiiii
I'm working on a client server application which work like messnger.. I was
able to capture the camera with no problem but now i want my my program to
listen to incoming connection and...
|
by: Marco |
last post by:
I have a problem with the establishement of a three way handshake
through raw socket.
The problem is that if in my application client I use the syscall
socket(AF_INET,SOCK_RAW,IPPROTO_RAW)
the...
|
by: luckysanj |
last post by:
Dear Sir,
Can you give me idea about Live Radio Broadcasting. I want to implement the Live Radio Broadcasting link on my web page to play radio on live. So i need basic php code for this.
Your...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |