Jump to content

Getting A Result From Python Script On A Centos Server


TheNavigator

Recommended Posts

Hi there guys. I have a website on a shared hosting plan. I want to have some kinda of php script, that sends some text to a CentOS server, along with how much inputs will be needed, what to input on each input request, and the expected output.

 

However, I have no experience at all with making such communication between php and another Linux server, although I've worked on php and on a linux server, but stuff were local. Nothing was through a connection.

 

The server is already installed and working, and the site is there. All what's left is the code I put on the server and the code I add to the website. If someone can guide me through doing this I'll be quite grateful about it.

 

Thanks.

Link to comment
Share on other sites

What?

 

Okay, again. A php script that opens a connection with a server, sends it a string (X), an integer (n), (n) strings ( Y[ ] ) and a last string ( Z ). X is the code, n is the number of inputs needed, and Y is an array of that input and Z is the expected output. The server just returns a string containing "0" or "1". 0 if the output didn't match the sent 1, and 1 if it did. If an error happened, it returns an error string containing "0" then followed by the error.

 

Here's an example of a C code passed into the website script, although I want to deal with python, but I know C more than I know python.

 

A user will upload a file, say test.c containing the following.

 

#include <stdio.h>
#include <stdlib.h>
int main()
{
int x;
int y;

scanf("%d", &x);
scanf("%d", &y);

x = x+y;

printf("%d", x);

return 0;
}

 

So the php script will get that code from a file, say test.c, so here's a pseudo code of what would happen. Please note that the number of input and the input things will be statically saved, probably in a SQL database and the database will be queried for that.

 

String code = test.c;
string result = getResultFromServer(code, 2, 1, 3, 4);

 

For the server side,

 

compile test.c;
open (compiled file);
1
3
get output;
if (output == 4) return "1"; else return "0";

 

However, how can a "connection" be made to do this? How can the server make such stuff? I know nothing about how this can be actually implemented.

Link to comment
Share on other sites

You need to specify the protocol the client and the deamon should communicate in, and then look into socket programming. It's very simple in PHP at least, and shouldn't be much more difficult in C. The syntax is quite similar, at least.

The main problem is that you haven't defined this communication in any way, just that it should be there. We cannot specify the protocol for you, that's something you have to do yourself as you're the only one how knows the full requirements for it.

Link to comment
Share on other sites

This is my problem actually. I know nothing about protocols and therefore I don't know what shall I do or why shall I use X and not Y. I don't know what programming language to use to write the responder on the server, and I don't know how to make that protocol secured. That's the point. I know nothing about communication :|

Link to comment
Share on other sites

Then you need to read up on how to do this, and how IP works.

This is actually one of the few cases where you're completely free to do whatever you like, at least as it's reasonably well written. The protocol definition and languages in use are choices completely up to you; You can use a predefined syntax (or syntax framework like XML, JSON or similar) for your protocol, or you can define it from scratch.

 

The OS in question is almost quite irrelevant, at least for your applications. The only effect it has is what libraries are available for your use, if you use a compiled language for the daemon. Most of the time, however, the differences are academical.

Though, that said I don't really see a reason for why you want to involve a second server into the mix. Might just be because I don't know all of the details.

Link to comment
Share on other sites

The second server is because that the web is hosted on a shared hosting account. The server is for compiling the code and returning the result.

 

Have you ever used TopCoder, USACO or something like so? They have a server for compiling the code, and a website. We can't put the website on the server because of the low internet connection, and we can't put the compiling thing on the web hosting because of permissions and stability too.

 

I don't know how to describe this simpler to be honest. It's just an "upload file" on a website, the website sends the file to the server with some arguments, and receives an argument which it directly displays. That's all.

 

About XML or JSON, I've already used them before in Objective-C but they won't be really helpful here. I would go for defining my own protocol.

 

For the OS, actually it would be different for installing scripts, etc. For Windows (for example) installing apache is much more different than Linux, so I wanted to point that out.

 

So, how to start making such protocol? I need to open a port first, right?

Link to comment
Share on other sites

OAuth is probably just about the best solution you can get today for server-to-server identification, the rest is completely up to what you want. As I said, you'll have to read more about protocols in general, and probably how IP (Internet Protocol) works. Or whatever other protocol you decide to use for your transport layer.

 

The problem with this thread, as I see it, is that you have four (five) different topic mixed into one huge (and confusing) problem description: You have remote compiling (and unit testing), server-to-server identification, protocol declaration, and code upload/form processing. At least two of these are huge topics, with a lot of details and planning needed to solve properly.

Split the tasks up into their individual domains, and work to solve them one by one. This we cannot do for you, as a lot of the work require intimate knowledge of the requirements of the completed solution.

Link to comment
Share on other sites

I got your point. Okay I'll make this topic a little bit more specific.

 

I want to making something like SMTP, I send a request, with username and password, the server verifies, I send a request of mail, I receive a boolean if it's successful or not, and then everything's disconnected. I want to know how to let the server authenticate the username and password, how to make a php script that sends that information, and how to tell the server and the php (disconnect when you receive/send bla bla bla) :)

 

However, I didn't read about OAuth yet. I will now.

Link to comment
Share on other sites

You make that script as you make any others; A web page is basically just a protocol between you (the developer) and the user (browser). Where the users actions trigger a command to be sent to your server, by which the server-side code decides how to respond back.

The trick is to decide what protocol to use for the transport layer, knowing how it works, and (most importantly) defining what you need your protocol to communicate. This last step seems to have been handled already, more or less, and entails a very simple protocol.

Edited by Christian F.
Link to comment
Share on other sites

You can use any language you like, as long as it supports sockets. Using one you're already familiar with is generally the best solution.

Also, it's not as much as "installing" a socket server, as it's "writing" one. Any server application that accepts a connection over a network, or even most local-only daemons, is by definition a "socket server". As I said, read up on how TCP and IP ("Transport Control Protocol" and "Internet Protocol") works. Then you'll understand this a lot better.

Link to comment
Share on other sites

kicken and recurse recommend cURL, so it looks like that's what I'll go with (or try) as that python thing has a lot of errors.

 

I installed php and httpd on the server, however, when I go to the browser, enter the IP there, nothing appears. recurse asked me to edit /etc/httpd/conf.d/httpd.conf but it wasn't there. Only mod_dnssd.conf, README and welcome.conf were there.

 

The service is started and running, just saying.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.