English 中文(简体)
UDP A. 住房规划
原标题:UDP Socket Programming with PHP

我在贾瓦挖掘了一台服务器,该服务器聆听了民盟第100号停泊港的要求,并在民盟第200号停泊港做出反应。

现在,我需要写进PHP的客户,该客户应当将其申请放在第100号港,并在200年收到答复。

我的方案能够向100号港口的服务器发出这一请求,服务器也在200号港口做出反应。 但我的购买力平价方案没有得到回应。 它正在等待。

有趣的是,如果我向提出请求的同一港口发出回复,那么我的住房价格指数就能够接收。 但服务器设计是使用两个港口。 一个即将到来,一个即将结束。

这里,我的个人财产法典

<?php
class SocketHandle {
    public function requestService($message) {
        //  Choose proper domain
        $domain = (strtoupper(substr(PHP_OS, 0, 3)) ==  WIN  ? AF_INET : AF_UNIX);
        $socketHandle = socket_create($domain, SOCK_DGRAM, SOL_UDP);
        $serverIP = "127.0.0.1";
        $serverSendPort = 100;
        $serverRecvPort = 200;
        socket_sendto($socketHandle, $message, strlen($message), 0, $serverIP, $serverSendPort);
        $response = "";
        socket_recvfrom($socketHandle, $response, strlen($message), 0, $serverIP, $serverRecvPort);
        return $response;
    }
}
?>

and服务器代码

class UDPServer { 
    public static void main(java.lang.String args[]) throws java.lang.Exception{ 
        try{ 
            java.net.DatagramSocket serverSocket = new java.net.DatagramSocket(100); 
            java.net.DatagramSocket serverSocket200 = new java.net.DatagramSocket(200); 
            byte[] receiveData = new byte[1024]; 
            byte[] sendData  = new byte[1024]; 

            while(true){ 

                receiveData = new byte[1024]; 

                java.net.DatagramPacket receivePacket = new java.net.DatagramPacket(receiveData, receiveData.length); 

                java.lang.System.out.println ("Waiting for datagram packet");

                serverSocket.receive(receivePacket); 

                java.lang.String sentence = new java.lang.String(receivePacket.getData()).trim(); 

                java.net.InetAddress IPAddress = receivePacket.getAddress(); 

                int port = receivePacket.getPort(); 

                java.lang.System.out.println ("From: " + IPAddress + ":" + port);
                java.lang.System.out.println ("Message: " + sentence);

                java.lang.String capitalizedSentence = sentence.toUpperCase(); 
                sendData = capitalizedSentence.getBytes(); 

                //java.net.DatagramPacket sendPacket = new java.net.DatagramPacket(sendData, sendData.length, IPAddress,  port); 
                java.net.DatagramPacket sendPacket = new java.net.DatagramPacket(sendData, sendData.length, IPAddress, 200);

                java.lang.System.out.println("Sending : " + capitalizedSentence);

                //serverSocket.send(sendPacket); 
                serverSocket200.send(sendPacket);
            } 

        }catch (java.net.SocketException ex) {
            java.lang.System.out.println("UDP Port 100 / 200 is occupied.");
            java.lang.System.exit(1);
        }
    } 
}

这里是我的 Java服务器的产出。

>java UDPServer

Waiting for datagram packet
From: /127.0.0.1:54491
Message: Hello
Sending : HELLO
Waiting for datagram packet
最佳回答

在短链氯化石蜡中,它没有听不到1024年的港口。 如果你使用1024以上的港口,它将工作。

问题回答

socket_recv from port paramile set the remote port that the response needs to come from, so no t adopt any here. 聆听港口是在接听电话时铺设的,因此它正在100港听听。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签