0
votes

Im looking for feasibility of calling C object(for copying a file from client to server) via Javascript Eventsource.

Ex:

I have a C-Client Program which can be executed as below:

./client ip

executing above file will send a file from client machine to server running at port 8888.

Server will be running at 8888 will receive the file and will write at /folder1/receivedfile.

./server ip

I need to do this in Javascript Event source.

Javascript code example:

if(window.EventSource){
var source =new EventSource("c-object");
}else{
// Result to xhr polling :( xhttprequest
}

1

1 Answers

0
votes

It is feasible. Your second line would be something like this:

var source = new EventSource("http://myserver.example.com:8888/c-object");

Your server must be running HTTP protocol, of course. If going down this route, be aware that calling a resource on a different origin will need all the CORS workarounds. In this case the resource is c-object, and the different origin is because of using a different port to where the HTML was served from.

Alternatively you could use Apache, and start c-object as a cgi program. Then it just needs to interact on stdin/stdout.

But, taking a step back, are you sure it is EventSource you want? If you are just trying to send a signal to the server to tell it to copy a file, and not receiving any data, then use a normal AJAX request. SSE is for the server to stream data to the client, one-way, continuously. After the initial connection is made, SSE cannot send anything to the server.