answersLogoWhite

0

//Get and display distributed message

#include <sys/types.h> // for type

#include <sys/socket.h> // for socket API

#include <netinet/in.h> // for address

#include <arpa/inet.h> // for sockaddr_in

#include <stdio.h> // for printf()

#include <stdlib.h> // for atoi()

#include <string.h> // for strlen()

#include <unistd.h> // for close()

////////////////////////////////////////////

char *multiHostAddress = "239.255.10.10";

void getEcho (int sock)

{

struct sockaddr_in read_EP;

int stop = -1;

char *msg;

printf ("Waiting for message... \n");

while (stop < 0)

{

msg = (char *)recvfromDST (&read_EP, sock);

if (msg != NULL)

printf ("%s==>%s\n",inet_ntoa(read_EP.sin_addr),msg);

else

stop = 0;

}

}

////////////////////////////////////////////

int main(int argc, char **argv)

{

int sockMulti;

int readPort;

struct sockaddr_in EP_multi;

struct ip_mreq request;

unsigned char TTL=3;

//-------------

int MC_socket;

struct sockaddr_in server_EP, sender_EP;

char msg [60];

char *readmsg;

int port;

int stop = 0;

//--------------

//--------------

if (argc != 4)

{

IO_error(1,"Need host, send port and receive port.(e.g localhost 9000 9001)");

}

//--------------

else

{

//-----------------------------

//Send msg to server

port = atoi (argv[2]);

printf ("TCP Client to send message to Server %s at Port %d \n", argv[1], port);

setHostByName (&server_EP, argv[1], port);

MC_socket= sockTCP_create();

sock_connect(MC_socket, &server_EP);

while (stop 0);

}

//Receive msg from server

readPort = atoi (argv[3]);

printf ("Multicasting receiver at ports %d \n", readPort);

//Initialisation

sockMulti = sockUDP_create();

sockUDP_reuse (sockMulti);

setHostByAddr (&EP_multi, "any", readPort);

sock_bind (sockMulti, readPort);

sockUDP_join (sockMulti, multiHostAddress,&request);

//Use service

getEcho (sockMulti);

//Finalisation

sockUDP_drop (sockMulti, request);

close(sockMulti);

//----------------------------------

}

sock_shutdown(MC_socket, 1);

readmsg = NULL;

while (readmsg != NULL)

readmsg = (char *)readMessage(MC_socket);

//-----------------------------------

}

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

How do you get no class?

I know it is impossible but there is a thing to make you have no class. First buy a new class in a chat server then you have to open a new tab then login in a non-chat server in the first tab equip the class and in the second server sell the class. Then logout of both tabs and close the second tab login in the first tab and go in any server and there you have it no class if it does not work try loging out and go to the server you bought your class and you have it. If it still does not work try again or go ask again cause my way might not be fully detailed.&lt;(^_^)&gt; :):):):):):D:O:d


What is a daemon thread?

A daemon thread is often called a "service thread" or a "nonessential thread". The other kind of thread is often called a "user thread."The JVM will exit when all user threads have returned from their run methods. Once all of the user threads have returned, any active daemon threads will be forced to stop running.Let's look at an abstract example to see the difference... Pretend you have written a client-server GUI-based chat client. You'll typically have at least one thread sitting around and listening for input from the other program (the server will listen for input from the client and the client will listen for input from the server). These threads can be set as daemon threads, because you don't want the JVM to keep executing if those are the only threads left.Not let's look at the GUI for your programs. These will be run in a user thread, since you want to make sure that the JVM does not exit until the GUI thread finishes running (you will generally stop these threads from running when the user clicks to close the window).


What is the HTML to get a chatbox?

HTML is not a programming language, so you cannot create any applications with it. It is just for formatting the look and design of a page. To get a page to do something needs programming code. There is no HTML code that would create a chat room, so you would have to use a server scripting language like PHP or ASP.


What are advantages and disadvantages of lotus notes?

1. It's more secure then MS-exchange &amp; Outlook , because if have a Domino server then only you can access your Archive , and mails, calender, etc..... 2. Lotus Notes have a Same time messenger. That we can chat with internal users &amp; external users


How do you make your own chat room on imvu?

Well, all you do is invite the friends you want to be in the group chat.

Related Questions

What is best irc server for adult chat?

The best IRC server for Adult Chat is Collarspace. We offer a web-based chat client as well as access through your preferred IRC Client. Visit us on Collarspace or point your chat client to chat.collarspace.com on port 6667 and join us today!


What is an IRC client?

An IRC Client, or Internet Relay Chat Client, is a program used to connect to an Internet Relay Chat server so that a user can chat via text-based messages in real-time.


How do you chat on server?

chating in cysero server is like on other chat enabled server i hope that my answer is correct


How do you get a chat bar if you have ultimate safe chat?

You can't if you are in a Server that is an ultimate Safe Chat Server. It has a Speech Bubble next to each server if it's Ultimate safe chat. If not, you can use the chat bar.


How do you chat on cysero server?

chating in cysero server is like on other chat enabled server i hope that my answer is correct


How do you turn on chat on a Minecraft server?

On a Minecraft server, chat is always on. If one of your friends can't chat, then it is a problem on their end.


Can you write your own words in club penguin?

yes, unless when you made your penguin you went under ultimate safe chat, because then they write the words for you. Or if when your going into a server you click the server with a speech bubble.


How you can make multiuser in your chat?

It depends on which chat program you are using. In Skype, there is an + icon in the top right corner of each conversation. You would click that, then the add people option.


What is the best chat program?

I think that the best chat for local networks - MyChat. This is the new products on the market. Chat has a client-server structure. Small value distinguishes this product from other products. Chat can withstand more than 1000 users. Site - http://www.nsoft-s.com/en/aboutmychat.html


How can you get a club penguin chat bar?

Go onto a server without a chat bubble next to the server name.


How do you get the chat bar on club penguin?

if you went on a server and it had a speech bubble (safe chat) the chat bar is not there.If you went on a server without the speech bubble the chat bar would be there.


Why doesn't my chat show in the chat box?

You chat might not show on Chat box. It could be due to an error that it can't connect to server. The internet connection could not connect to the server.