Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中向Supersocket发送请求时关闭Php客户端#_C#_Php_Supersocket.net - Fatal编程技术网

C# 在C中向Supersocket发送请求时关闭Php客户端#

C# 在C中向Supersocket发送请求时关闭Php客户端#,c#,php,supersocket.net,C#,Php,Supersocket.net,我的服务器是c#,客户端是PHP。我使用Supersocket[实现客户端和服务器之间的通信 C#带超级存储库-服务器端 using System; using System.Collections.Generic; using System.Linq; using System.Text; using SuperSocket.SocketBase; using SuperSocket.Common; using SuperSocket.SocketEngine; using SuperSock

我的服务器是c#,客户端是PHP。我使用Supersocket[实现客户端和服务器之间的通信

C#带超级存储库-服务器端

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase;
using SuperSocket.Common;
using SuperSocket.SocketEngine;
using SuperSocket;
using System.Configuration;
namespace ConsoleApplication1
{
class Program
{
    static void Main(string[] args) 
{
        Console.WriteLine("Press any key to start the WebSocketServer!");
        Console.ReadKey();
        Console.WriteLine();
        var appServer = new AppServer();
        //Setup the appServer
        if (!appServer.Setup(2020))
        {
            Console.WriteLine("Failed to setup!");
            Console.ReadKey();
            return;
        }
        appServer.NewSessionConnected += new SessionHandler<AppSession>(appServer_NewSessionConnected);
        appServer.NewRequestReceived += new RequestHandler<AppSession, SuperSocket.SocketBase.Protocol.StringRequestInfo>(appServer_NewRequestReceived);
        appServer.SessionClosed += new SessionHandler<AppSession, CloseReason>(appServer_SessionClosed);
        Console.WriteLine();

        //Try to start the appServer
        if (!appServer.Start())
        {
            Console.WriteLine("Failed to start!");
            Console.ReadKey();
            return;
        }

        Console.WriteLine("The server started successfully, press key 'q' to stop it!");

        while (Console.ReadKey().KeyChar != 'q')
        {
            Console.WriteLine();
            continue;
        }

        //Stop the appServer
        appServer.Stop();

        Console.WriteLine();
        Console.WriteLine("The server was stopped!");
        Console.ReadKey();
    }

    static void appServer_NewSessionConnected(AppSession session)
    {
        session.Send("Swelcome");
    }

    static void appServer_SessionClosed(AppSession session, CloseReason value)
    {
        session.Send("Server: " + "welcome");
    }

    static void appServer_NewRequestReceived(AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo)
    {
        try
        {
            switch (requestInfo.Key.ToUpper())
            {
                case ("ECHO"):
                    session.Send(requestInfo.Body);
                    break;

                case ("ADD"):
                    session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
                    break;

                case ("MULT"):

                    var result = 1;

                    foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
                    {
                        result *= factor;
                    }

                    session.Send(result.ToString());
                    break;
                default:
                    Console.WriteLine("Default");
                    session.Send(requestInfo.Body);
                    break;
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

}
}

我从服务器到客户端(PHP)获得了消息。但是当我尝试从PHP向c#发送消息时,SessionClosed事件触发,错误显示“客户端关闭”。任何人都可以帮助我通过Supersocket将php客户端与c#服务器进行通信。提前感谢。

在服务器配置中增加MaxConnectionNumber对我有效。

在服务器配置中增加MaxConnectionNumber对我有效

class XoneDataReciver
{
var $socketPtr;      
function OpenConnection($server, $port)
{
    $this->socketPtr = fsockopen($server, $port, $errno, $errstr, 0.4);
    if (!$this->socketPtr) {
        echo "Network down. Please refresh the page again or try again later."; exit();
    } else {
        return 0;
    }
}


function MakeRequest($action, $params = array())
{
    if (!$this->socketPtr)
        return "error";               
    $this->sendRequest($action); //Error - Client closing

    return $this->readAnswer(); // Got msg from server 
}



function sendRequest($request)
{   
    fputs($this->socketPtr, $request);
}


}
$xone_ip ="127.0.0.1";
$xone_port = "2020";
$xonerequest   = new XoneDataReciver;
$xonerequest->OpenConnection($xone_ip, $xone_port);
?>