duancong7573 2010-04-21 10:25
浏览 59
已采纳

PHP客户端和Java Server之间的客户端 - 服务器网络

I have a university project which is already 99% completed. It consists of two parts-website (PHP) and desktop (Java).

People have their accounts on the website and they wish to query different information regarding their accounts. They send an SMS which is received by desktop application which queries database of website (MySQL) and sends the reply accordingly. This part is working superbly. The problem is that some times website wishes to instruct the desktop application to send a specific SMS to a particular number. Apparently there seems no way other than putting all the load to the DB server... This is how I made it work. Website puts SMS jobs in a specific table. Java application polls this table again and again and if it finds a job, it executes it. Even this part is working correctly but unfortunately it is not acceptable by my university to poll the DB like this. :(

The other approach I could think of is to use client-server one. I tried making Java server and its PHP client. So that whenever an SMS is to be sent, the website opens a socket connection to desktop application and sends two strings (cell # and SMS message). Unfortunately I am unable to do this. I was successfully to make a Java server which works fine when connected by a Java client, similarly my PHP client connects correctly to a PHP server, but when I try to cross them, they start hating each other... PHP shows no error but Java gives StreamCorruptedException when it tries to read header of input stream.

Could someone please tell what I can try to make PHP client and Java server work together? Or if the said purpose can be achieved by another means, how?

Regards, Yasir

  • 写回答

2条回答 默认 最新

  • duandiao3961 2010-04-21 11:11
    关注

    Wait... are you using object streams? According to the java documentation StreamCorruptedException is "Thrown when control information that was read from an object stream violates internal consistency checks." I doubt your PHP app is sending what Java considers a serialized object. Why don't you go low-tech and read a string? The following had worked for me back in the day:

           ServerSocket serverSocket = new ServerSocket(port);
           Socket clientSocket = serverSocket.accept();
           BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    
           while((inputLine = in.readLine())!=null)
          {
            //Do whatever
          }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题