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.
Related
I have a simple networking program for sending and responding to HTTP requests/responses. However, if I wanted to send a HTTP or another request via a SOCKS5 proxy, how would I go about this? I'm using C Unix sockets.
I could solve this by creating a proxy server in Linux. However, my intention is so that I can send this to a proxy server I do not own so that it can be forwarded to the destination server. I couldn't seem to find a library. I found an RFC for it which I've read https://www.rfc-editor.org/rfc/rfc1928.txt , but i'm still not 100% unsure how to format my request.
Am I supposed to send the segments for the handshakes as hex? If so, would I send a string of hex 0F3504 or \x0F \x35 \x04 or 0x0F3504? Another question is do i need to denote that header = value in the message, or does the SOCKS5 server know what header i am referring to by the position of the byte it is looking at from the message I've sent?
Any clear up would be very much appreciated
Some time ago I wrote an open source C library that may help you: https://github.com/brechtsanders/proxysocket
Maybe you can use the library. Its quite easy, just replace the connect() with stuff from the library and for the rest you can keep the rest of your code that uses the socket that is returned.
Or you can take a peek in the code to see how it's done there.
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.
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++?
I am writing FTP client in C. I am not making any changes to Server program.
I want to get specific amount of data from a file on server.
Suppose I have a file on server and I want to read last 100 bytes from the file. I don't want to read whole file.
I am able to get whole file using
RETR filename but I didn't find any way to read specific amount of bytes.
Is there any way to do this for a standard FTP server?
Is there any way to do this for a standard FTP server?
No. You can tell the server the position where it should start with the REST (restart) command, but you cannot tell it how much data it should send. All you can do is close the data channel after you've received the amount of data you want. The FTP server will probably complain about this because it received a RST (writing against a closed socket) but in most cases this should not cause problems.
I am asked for an assignment that requires implementation of FTP protocol. I have gone through the documentation given at RFC959.
I am confused with a couple of implementation details
1)If a file needs to be transferred, what function can be used. can a simple send() function be used for a non text file.
2) Is it possible to get a good tutorial that speaks about implementing Modes and file structures, and to specify, which are essential.
hope to get a reply soon.
FTP transfers file through a plain TCP connection, and you can transfer any kind of file with it. There is no difference between text files and binary files, they are all just sequence of bytes.
For the file transmission is sufficient to open a connection and call the write function many times until the entire file is transmitted (check the return value of write to know how many bytes it sent).
The rest of the FTP protocol is text based and is sent to a different port.
There is a good tutorial on using FTP directly through netcat, that can be useful to understand how things work. Understanding active and passive mode can also be useful, since you are going to implement at least one of them.
Also, use wireshark to follow a TCP stream and see the data you are sending/receiving, it can be very useful in debugging.
The protocol implementation won't give you a file structure. The protocol is here to define some rules and states.
The dev/prog part is up to you. You just need to respect the FTP protocol in order to gain the normalization and the compatibility with other client/server.
Best regards