LINK URL LINUX

Hi,
I will explain my code
work in Linux (ubuntu) and c ++ (gcc). I have a code with sockets which makes the function of client-server and I wonder if you can pass through a socket to the client (in my case firefox) html code because I want to show a link to a file in
firefox!
for example:
strcpy(buffer,"<html><body><a href='A.txt'>EN</a></body></html>");
write(id_socket,buffer,strlen(buffer));
this show in firefox all code, all string! doesn't make the link!

thankyou!!
I'm not sure I completely understand you. But I think you want to pass a link to a text file through your socket so that you can click on the link in Firefox to view the file?

Well you can certainly pass the link to Firefox as in your example. But your server would have to know how to deal with the request from Firefox to view the file that you passed the link to. Unless you serve that file up by other means (local web server...?).

Also, your example will not work unless you obey the rules of HTTP. First you need to send out the header information BEFORE you sent the HTML.

Something a bit like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <string>
#include <sstream>

std::string html = "<html><body><a href='A.txt'>EN</a></body></html>";

std::ostringstream response;

response << "HTTP/1.1 200 OK\r\n"
response << "Content-Length: " << html.length() << "\r\n";
response << "Content-Type: text/html\r\n";
response << "\r\n"; // end of headers
response << html;

write(id_socket, response.c_str(), response.length());
Last edited on
Topic archived. No new replies allowed.