socket_io使用多个进程和端口

问题描述

我正在server.py中创建2个子进程:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace ConsoleApplication167
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XmlReader reader = XmlReader.Create(FILENAME);
            XmlSerializer serializer = new XmlSerializer(typeof(extensionAttributes));
            extensionAttributes attributes = (extensionAttributes)serializer.Deserialize(reader);

        }
    }
    public class extensionAttributes
    {
        [XmlArray("paymentAdditionalInfo")]
        [XmlArrayItem("item")]
        public List<paymentAdditionalInfo> paymentAdditionalInfo { get; set; }
        [XmlArray("giftCards")]
        [XmlArrayItem("item")]
        public List<giftCardsItem> giftCarItem { get; set; }
    }
    public class paymentAdditionalInfo
    {
        public string key { get; set; }
        public string value { get; set; }
    }
    public class giftCardsItem
    {
        public int id { get;set;}
        public string code { get; set; }
        public int amount { get; set; }
        public int baseAmount { get; set; }
    }

 
}

根据给定的参数可能监听不同的端口。然后在client.py中,我有

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        const string INPUT_FILENAME = @"c:\temp\test.xml";
        const string OUTPUT_FILENAME = @"c:\temp\test1.xml";
        static void Main(string[] args)
        {
            XmlReader reader = XmlReader.Create(INPUT_FILENAME);
            XmlSerializer serializer = new XmlSerializer(typeof(extensionAttributes));
            extensionAttributes attributes = (extensionAttributes)serializer.Deserialize(reader);

            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            XmlWriter writer = XmlWriter.Create(OUTPUT_FILENAME,settings);
            serializer.Serialize(writer,attributes);
        }
    }
    public class extensionAttributes : IXmlSerializable
    {
        public Dictionary<string,List<Dictionary<string,string>>> dict { get;set;}


        // Xml Serialization Infrastructure

        public void WriteXml (XmlWriter writer)
        {
            foreach (keyvaluePair<string,string>>> key in dict)
            {
                XElement attribute = new XElement(key.Key);
                foreach (Dictionary<string,string> itemDict in key.Value)
                {
                    XElement items = new XElement("item");
                    attribute.Add(items);
                    foreach (keyvaluePair<string,string> item in itemDict)
                    {
                        items.Add(new XElement(item.Key,item.Value));
                    }
                }
                attribute.Writeto(writer);
            }
        }

        public void readxml (XmlReader reader)
        {
            XElement elements = (XElement)XElement.ReadFrom(reader);
            foreach (XElement element in elements.Elements())
            {
                string name = element.Name.LocalName;
                List<Dictionary<string,string>> childDict = element.Elements("item")
                    .Select(x => x.Elements()
                        .GroupBy(y => y.Name.LocalName,z => (string)z)
                        .ToDictionary(y => y.Key,z => z.FirstOrDefault())
                        ).ToList();
                if (dict == null)
                {
                    dict = new Dictionary<string,string>>>();
                }
                dict.Add(name,childDict);
            }
        }

        public XmlSchema GetSchema()
        {
            return(null);
        }


    }
}

将数据发送回server.py,即:

@app.route("/dataVis",methods=['POST'])
def draw():
    config_data = {
    "/dev/tty.BITalino-73-36-DevB": {
        "port": 8020
    },"/dev/tty.BITalino-6E-2A-DevB": {
        "port": 8020
    }
    }

    for macAddress in list(config_data.keys()):
        subprocess.Popen("python client.py " + macAddress + " " + str(port) + " " + str(channels) + " " + str(SR) + " " + str(nSamples),shell=True)
    return render_template("realTimeDataVis.html",host_ip=json.dumps(str(host_ip)))

哪个将我的数据发送到我的javascript文件

PORT = sys.argv[2]
with SocketIO(host_ip,PORT,LoggingNamespace) as socketIO:
   socketIO.emit('dataReceiver',send_data) # send data

我的代码当前仅适用于一个进程。我应该尝试使用2个不同的端口吗?我该怎么办?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)