doutangxi2144 2011-08-02 02:24
浏览 48
已采纳

带有套接字的Java客户端和PHP服务器

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?