I have been searching for hours now and just need some guidance about my situation. I want to create a simple client/server program. I was originally planning on doing them both in java, but I bought a shared hosting account from godaddy a couple of weeks ago and they have disabled java for new accounts. So, I guess my next best choice, and in a language that I'm somewhat familiar with, is PHP. I have been following the tutorial on sockets from the java site, and have the java client made. I've been trying to convert the server part of the example to PHP. Apparently, godaddy will let you use fsockopen() for sockets on a shared server. I guess what I need to know is, is this possible, and how do I run the php file once it is made? The example says I need to start the server program before I run the client. I'm not sure of how to do that though.
2条回答 默认 最新
- dousou1967 2011-08-02 02:41关注
I would NOT use raw sockets to do this. Instead use JSON over HTTP because PHP supports processing HTTP without any special consideration. It's simple to run your PHP pages on the hosted apache instance on GoDaddy or Amazon EC2. Sure you can use sockets, but very very few people actually do that. Massively more people process and respond to HTTP with PHP. That means you'll find vastly more people who can help answer your questions if you follow the herd here. Also there are API libraries on both sides for doing this easily. Using sockets comes with plenty of things you'll have to do yourself or suffer through all the strange bugs that comes with working with raw sockets for the first time.
Also JSON processing is easily supported by both Java and PHP to it's very easy to send the data to the client and server using that.
Well you can certainly use PHP on the backend and Java on the frontend if you like, but I'd suggest canceling your Go-Daddy account and get an Amazon EC2/S3 account because you get a full machine dedicated to whatever you want to put on it. So if you want to do Java on the backend you can just by installing the JDK, Tomcat, etc yourself on the amazon instance and you're good to go. You can also host PHP on there too. There is even plenty of AMI instances pre-installed for Java or PHP stacks.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报