Implement the storage of messages in the chat (RPC) - database

I must implement the chat using Sun RPC (first write XDR file, in the next place generate .c codes by dint of rpcgen). I would like to know how I should implement the storage of messages for users who are registered, but they were OFFLINE, when other users were writing. So that the user, when he will ONLINE, was able to read everything that was written without him in the chat.
I write in Ubuntu. Thanks.
Sorry for my English.

As the name says, Xdr is for external data representation.
You can easily store the messages as string in a DB, and when an user logs in, you can create the xdr stream and send to him all messages.

Related

How are messages marked as read using discord.js?

I've written a chat client extension for visual studio code, using the https://discord.js.org/ framework.
At the moment I'm tracking the last read message in each channel manually, but the message and channel objects have an 'acknowledge' method to mark them as read.
It seems that this should be the correct way to mark messages as read, but I can't work out how to determine which messages have been read when fetching the messages from the server?
There are no events or any sort of way to see if a message was read sadly. It is a feature that I would like implemented, but for the time being there is no way to do it.
Wishing you luck,
Zaedus

How to filter anonymous SIP messages / invites on Asterisk

I have a CentOS 7 installation runnning Asterisk 14.0.3.6 with pjsip enabled and FreePBX for a UI. For a new project we will have many devices in the field which will want to be able to send a sip message without registering(in a separated network with their own router) to a registered SIP client in our environment (like a message receiver). After receiving the message we want to be able to initiate a call session if necessary.
The first challenge is to filter the sip messages / invites from sources I don't want to receive anything from. My plan is to register the devices in the database and match one or more values from a specific device to the incoming messages / invites and accept or decline these based on the existing values.
I'm a beginner to C and Asterisk, installing the environment is all experience I have so far. I do know how to code since I'm a C# programmer. Now I'm looking for the c file to edit so I can filter incoming invites or messages based on an array of values but I don't know which file and function is responsible for handling this.
Any tips are greatly appreciated.
Asterisk have built-in registrator. It will refuse messages from not-registered peers automaticaly.

Sending images to server?

I have to write a C++ applicaton that has to read images from a local directory on client computer (linux, ubuntu) and send them to a server (linux, ubuntu).
There will be almost 1000 of such clients.
Assuming that the rest of my program is written in C++ I need some hint on what library+technologies to use to achieve this goal?
That would depend on a number of variables.
First, determine what type of format does the server accept? Is it SOAP or not? If yes, you can stream data to the server. Otherwise, you need to read the entire file first and then, send it.
Second, here is a very good article on how to create a web request in C++. Have a look at it: How do you make a HTTP request with C++?

using client server text chat to provide audio support

I have implemented a multiple client-server text chat in c over Linux(using TCP sockets). Now i want to use it to support audio files as well.After going through stack overflow i found that this can be achieved by sending a file from client to server and server sending same file to all clients.
Now my question is
how can the server(and clients) differentiate whether it is receiving ordinary text data or (the server)has to pack the receiving data into a file?
Also till now what i have is that client enters text and the server receives it.How can i provide an option to client to send either a file or text.I was thinking of using switch case(like 1 for file ,2 for text) but that is not a good interface?
You have two questions here.
For 1: You will need to decide how they differentiate text data from file data, by sending extra bytes. One possible scheme is the following:
For chat messages:
Send the byte 1 (meaning this is a chat message).
Send the message.
Send a \n.
For files:
Send the byte 2 (meaning this is a file).
Send the length of the file, as an 8-byte integer.
Send the file contents.
For 2: That is also up to you. I would suggest that your client works the same way it does already (anything the user types is a chat message) unless the user types a special command, like "/file". If the user types the command, then the client can ask the user for which file to send, and send it.
I suggest you use an industry-standard way of representing different part types. Have a look at MIME encoding. Your normal messages would be in (e.g.) text/plain. This is (broadly) how HTTP determines what to do with the byte-stream it receives from the server.

Best way to write a ftp client program to list files on the server?

I am trying to write a client-server program in C in windows. The objective is to receive the directory listing from the server. Now I was trying to develop the client-server in such a way to utilize most resources.
One way to implement is that server makes a single send() call to send info of a single file. So if there are 100 files, it makes 100 calls. But I feel its a wastage of network resources. As far as I know the buffer size for send() or recv() in windows is 8kb. But the info of a single file will be hardly 1kb. So is there a way to make send() call to send multiple files info (file info are stored in structures. So they basically form a linked list) ? May be I can send info of atleast 8 files in a single Send() call. That should reduce the total send() calls to maximum 13.
So basically is there a way to send a linked list via send() ?? Plz let me know if you can think of any alternative method.
Good question! +1 for that.
But do you really want or need to write your code to use Winsock? There are good reasons to do so -- including that it's fun and a challenge. But if you don't need to, you might want to consider using the libcurl ftp library, which is free, multi-platform (including win32, of course), just works, and might make your job a lot easier.
The only way I know of to do this with FTP is to use multiple connections to the FTP server. If this is allowed by the server, there can be a list performance boost because the many protocol exchanges needed to list a complete folder tree can be run in parallel.
Rgds,
Martin
TCP is a byte stream. There is no guarantee of a 1-to-1 relation between the number of items you want to send and the number of calls to send() (or recv()) you need to make. That is simply not how TCP works. You format the data the way you need to, and then you keep calling send() until it tells you that all of the data has been sent.
Regarding FTP, please read RFC 959 and RFC 3659 to learn how the ftp protocol actually works. Before the introduction of the MLST and MLSD commands, directory listings had no standardized format. FTP servers were free to use whatever formatting they wanted. Many servers just piped the raw data from the OS's own dir or list commands. Indy, for example, includes several dozen parsers in its FTP client for handling non-standard directory listings.

Resources