Input output of a text file from a online server - java

I am developing my first chess game with Qt( C++ GUI ). For that I would like to take input from an online server. It may be just a text file.( Actually Just to take the latest FEN string ). I don't know any way how can I interact with a server. Is there any simple way to interact with a web server or cloud server or just a way to download a text file then read it using Qt.
In case of failure, I can also change my platform from Qt to JAVA( as it is just to converting the whole algorithm ) but I just need a simpler way to text file input output say just like calling a function with suitable argument to get the text file. My biggest complication is the i/o. As I have mostly done the project in Qt, so solution with the Qt will be much appreciated.

In many such cases, it is best to have a look at the documentation of your framework, especially the example and help section.
For example, if you look at the Qt Network examples, you will find a lot of snippets, which implement any kind of network connection.
For how the interaction works, this may be too broad to answer. It depends on the server you want to connect to. Normally, there is a protocol specified, which describes the communication and how you have to query your information (simple HTTP request/response, JSON, TCP, ...).
That being said, Qt is perfectly capable of interacting with a server, and there is no need to switch to another language if you don't want to.

Related

How to Create a Web App to Compile and Run Java/C/PHP Code Online?

Though this is a question with broader scope, I want to write a Online Test Code for my company where people can be given questions to write code in java/php/c etc and the code run and compiles online. I have seen this happening in site like codeacademy, Udacity etc. Just want to understand the architecture behind it. I have searched a lot along the similiar lines a lot on Google but couldnt find a concrete answer. Though after reading bits and pieces here and there i understood that the code is sent to compiler on server and then the results are sent back. Not sure how exactly that happens. Can somebody point me to a starting point of it.
What you can basically have, according to a MVC pattern applied to a web architecture, is something like this:
A web application client-side, which allows the user to insert some code,
possibly leveraging Javascript for early syntactic check
A server endpoint,
receiving the inserted code as input from the client
The sequence of operations could be:
Server-side, the input is transformed into the appropriate structure for the target programming language, e.g. a Java class or a C module.
Possibly, more context is defined (e.g. a classpath).
Then, if the language is compiled, the compiler is invoked (e.g. javac or gcc). This can happen in several ways, e.g. exec in C or Runtime.getRuntime().exec in Java. Otherwise the code can be deployed on a server or some simulators can be run and passed the code.
Subsequently, the code is executed and output is intercepted (e.g. by directioning the console output to a file or just leveraging the target language infrastructure, like in this example). The execution can happen through command line (e.g. java) or via other tools (e.g. curl for running a deployed php code as it was a client browser accessing it)
Last step for the server is to send back the intercepted output to the client in a readable format, e.g. HTML. As an alternative, if you used Java, you could go for Applet, which doesn't change the basic architecture.
However, more in general, the point is that compilers and interpreters are base software. They are not intended for general users, which can easily live with the Operating System only. Therefore, "on line compiling", at the best of my knowledge, is something different from "posting code, letting it execute on a server, and visualizing the answer". Online compiling would mean distributing the responsibility of compiling across the network, which does make sense, but, in my opinion, it is not meant to use for demonstrative purpose (like you are mentioning).
I used domjudge for my company and customized it for my need.
PHP code is very well written. It is very modular and simple to adapt to your requirements.

P2P file sharing application

I have developed a simple file sharing application in java using TCP socket. Now, the question is how do i make this application P2P? Can Distributed Hash Table (DHT) do that or there are other options that i can implement in my application to make it P2P? I have been trying to get ideas on this for a long time but i only get more confused. Please help.
The Forest platform which is in early development is targeting applications like your. You might want to take a look at it.
The only problem is that it is still in development and is not yet usable. I advise you to keep an eye on it and try to use it once it reaches it first release.
EDIT to answer the comment under your question:
Your application would need to connect the some peers. Depending on how you choose them (random people or know contacts), you are using respectively a peer-to-peer ('p2p') network or a friend-to-friend ('f2f') network.
Forest is providing applications a f2f network, but application are free to route messages on the top of this network to achieve (anonymous) p2p.
For a classical p2p network, you would need to connect a DHT, and you would need to bootstrap to it via a (or some) server(s) which take part in the DHT.
In general, p2p application are not so simple to do, and you will need to deal with a lot more details here and there. If you really want to experiment with them, you can go to check existing DHT libraries and see how they work. You might first want to go to read the article on Wikipedia about Kademlia which is the base for the most used DHT algorithms.
Based upon your description it sounds like you have already created a simplistic P2P application. If you are looking for the next step I would setup a DHT server (bamboo). Next, modify your original application to get a list of available files from the DHT instead of connecting directly to the other peers for file lists.
I develop a simple P2P file sharing application in java too,but i find it hard . If you write it in java . You can search for Vuze or jBittorrent , which may help you develop it faster.

Best way to send "messages" from PHP to Java on the same workstation

What is the best way to send "messages" from PHP script to Java program in real time. PHP script and Java programs are both working at the same work station with OS Windows. Maybe some kind of client/server? The main feature is real time; that's why I don't want to use files.
PS: I'm going to send logger messages (php) and display (java) them at OS system tray tooltip.
PPS: I'm real noob in Java; it will be my first Java program. :)
Thank you.
You could use sockets (probably UDP, but depends on your needs). This way, if in the future you will need to put scripts and Java programs on different machines, you'll be able to do that without modifing the code.
In addition, once you established a communication protocol between client and server, this solution is language independent. So it's easy switch from PHP to another scripting language (the same for Java).
This depend on how heavy weight your application is.
If it is your first program and it is just a little project, a possibility is to open a socket on the server, connect to it with a client and send the data as a string, make your php program the client and java program the server.
Their are things that you can borrow to avoid doing everything on the low level. But they will add weight to your program, for example using a JSON/XML parser to serialize(make the messages into bytes readable on both side) the message instead of using your own format.
Or, use a framework like JAX-RS to quickly and easily (for people familar with it, you may need some time to understand it because it is quite different from writing plain java program) to build a little web service like professionals would do.
Possibilities are:
Send your data as a POST to jsp page.
Make your java code read your php logs.
use queuing systems like RabbitMQ, AciveMQ, Redis etc.
For simplicity use a database table as exchange medium.
It is also easier to debug.
(It is asynchrone, one side, PHP or Java, may be down. Performance is fast, as DB-Server will keep as much in memory.)

http server in php

I want to create http socket connection for server in php for multiple client . how can I do that ? I need some resource .
First I was trying to create server in java .I create a server in java . And trying to reach from android application .But server can't find any client.But when I create client in java .It was working. How can I solve that problem ???
Take a look at this article:
Writing Socket Servers in PHP by Zend
Also give a try with Google:
http://www.google.com/search?aq=0&oq=php+socket+server+mul&sourceid=chrome&ie=UTF-8&q=php+socket+server+multiple+clients
Personally I think this would be a pretty bad idea, as already mentioned it lacks Threading and it's Socket support (imo) isn't really that adaptable.
The only plus side is that you can use fork to fork off another PHP process to handle a client, but you're getting very complex.
Another language would be much more suited for this type of development.
Note that even if you did do this in PHP, you'd probably have to rely on external services anyway, and possibly even end up writing at least some code in another language anyway.
You're trying to use PHP to do what? Mind you, I like PHP and work with it almost every day, but please do remember PHP in and on itself is based on request and response, and not very suitable for long running processes. In a manner of exercise, it might be interesting, but if you're trying to write a webserver from scratch using PHP, you might want to reconsider your choice of language.
That said, you can create a socket acting as a server, and listen to incoming packets. I do still think you're reinventing the wheel though.
though i love php and java, i wrote my socket servers in c++ running under lamp in an amazon ec2 cloud server. it is very, very simple to code and debug and safe and you can practically just copy/paste examples.
in the long run, i will probably develop a java solution because of portability and scalability, but the initial effort to get a c++ solution working is just so much less than implementing a java solution...
the first thing you must ascertain (find out) is whether your server allows you to open custom ports. amazon ec2 does and at this point in time (feb13), can be used for free for 12 months.
so, this is for you if you are in a hurry:
this here set of examples has all that you need to be up and running in no time.
Judging from the question title (the rest only makes it more confusing) you could use an existing package like http://pear.php.net/package/HTTP_Server to implement a webserver in PHP. It already contains all the socket code to accept client connections and stuff.
So what i have to do to find the server from different client
"Finding" is too broad a topic. Depends on your actual setting. On a LAN there are some protocols for discoverability. Otherwise you should just rely on a fixed machine name and port number for your instantiated server. You can connect to it as e.g. http://localhost:8007/ or whatever you've predefined.

Simple middleware server for control and monitoring

I need a server. A simple one, to control a couple of computers. There are already a couple of programs in the lab, that perform some calculation and monitor tasks. They are executed on these computers. So I need a server to control them - to see the real time data from these computers, I want these programs to upload the calculation data to the server, upload also some files, that come together with this data. So the server needs to have a simple database. I also want to alter some of the calculation parameters in the realtime.
Because, you see, I'm a little tired of opening each computer with the terminal, looking at the process, get the files from each of the computers by ftp, put these files in the corresponding folder on the file storage, writing the schedule, when each program should continue it's work.
Maybe there is some middleware, that I can use for such needs? It should be simple and extensible. i thought of writing such server from scratch, it is not a big problem, but I have a severe time shortage and many other things to do.
And it would be cool, that this server would be developer-friendly. So I could just take it's API and write whatever I need.
I'm using Java, so it would be great, that this server would also "understand" Java. ;-) RMI is cool, but because of the network architecture, I'd prefer to use plain TCP/IP for these needs. Becacuse there is always problem with setting up RMI, when there computers are in differed subnetworks.
Thank you very much for your support in advance! Please help me, otherwise my girlfriend would break up with me, because I don't see her often spending most of my time at the lab... ;-(
I am almost finishing a software like that (actually 3 softwares) the server, the clients and the admin that logs into the server and command the clients.
My problem was specific so I had to go for a custom build from scratch (TCP/IP sockets). Its not hard, just write down the protocol.
If RMI doenst help you, then you must consider making your own proto, and you could exten and add new features later.
Maybe Google Protocol Buffers would help you to build your proto
http://code.google.com/p/protobuf/
Hmm, the two that spring to mind are Jetty and Glassfish. Depends a lot on what you need to do and how you want to go about it. Both are java based.
This seems like a problem for which Bundle-Bee was created for.

Categories