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 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办