php ve c # tcp iletişim sorunu

0 Cevap

Ok, well im working on a c# application that is acting as the server on port 4. And a php script on my website acting as the client. It can connect to the server but, when the server or client attempts to send data. The data turns out to just be random numbers and symbols. Scripts below

PHP:

$msg = $host + " connected;";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, $host, 4);
socket_write($socket, $msg, strlen($msg));
socket_close($socket);

C #:

while (heartbeat == false)
                {
                    if (listener.Pending())
                    {
                        heartbeatC = listener.AcceptTcpClient();
                        //heartbeatS = listener.AcceptSocket();
                        NetworkStream heartBeatStream = heartbeatC.GetStream();
                        string heartbeatEP = heartbeatC.Client.RemoteEndPoint.ToString();
                        string heartbeatIP = heartbeatEP.Remove(heartbeatEP.IndexOf(':'), heartbeatEP.Length - heartbeatEP.IndexOf(':'));
                        if (heartbeatIP == Dns.GetHostAddresses("***.********.com")[0].ToString())
                        {
                            dottime.Enabled = false;
                            Console.WriteLine("\nHeartbeat.");
                            bool heartbeatR = false;
                            while (heartbeatR == false)
                            {
                                if (heartBeatStream.DataAvailable)
                                {
                                    //StreamReader sr = new StreamReader(heartBeatStream);
                                    byte[] message = new byte[1024];
                                    int bytesRead = 0;
                                    bytesRead = heartbeatC.Client.Receive(message);
                                    ASCIIEncoding encoder = new ASCIIEncoding();
                                    string msg = encoder.GetString(message);
                                    Console.WriteLine("Server: " + msg);
                                    heartbeatR = true;
                                }
                            }
                            heartbeat = true;
                        }
                        else
                        {
                            heartbeatC.Client.Disconnect(true);
                        }
                    }
                }

0 Cevap