通过PCo(工厂连接)代理通知UDP-Server

时间:2015-05-12 13:38:54

标签: c# udp sap agent

我有问题。 关键是在SAP服务器和UDP服务器(Java应用程序)之间建立连接。 应使用这些工厂连接。 为此,我必须写一个所谓的代理人。

从互联网上寻找好几天并阅读了各种文件,但我找不到任何决定性的内容。

using System;
using System.Net.Sockets;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SAP.Manufacturing.Connectivity;
using SAP.Manufacturing.Connectivity.Tracing;
using SAP.Manufacturing.Connectivity.InternalConfig;
using System.Timers;
using System.Diagnostics;
using SAP.Manufacturing.Connectivity.Query.Text;
using SAP.Manufacturing.Connectivity.Query.Response;

namespace TTAgent
{
    [Agent(ChannelRetryModel = CommunicationChannelRetryModel.Passive)]
    [NotificationSupport]
    public partial class Agent : AgentBase
    {
        UdpClient client;

        public Agent() : base() { }
        public Agent(AgentInstance instance) : base(instance) { }
        public Agent(SourceChannel channel) : base(channel) { }

        protected override Aspects GetDefaultSourceChannelConfiguration()
        {
            Aspects aspects = new Aspects();
            Aspect aspect = new Aspect("TrainAgentConfig", "Configuration created at: " + DateTime.Now);
            aspects.Add(aspect);

            return aspects;
        }

        protected override void  StartInstance(Cache cache)
        {
            base.StartInstance(cache);
        }

        protected override void StopInstance() { }

        public override void EstablishConnection()
        {
            client = new UdpClient();
            System.Net.IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 6767);
            client.Connect(endPoint);
        }

        public override void RevokeConnection(){ }

        protected override bool  IsConnected()
        {
            byte[] dgram = new byte[66];
            client.Send(dgram, dgram.Length);
            return base.IsConnected();
        }

        new public void Dispose() 
        {
            client.EndSend(null);
            client.Close();
        }
    }
}

我将PCo中的代理绑定为源并创建一个实例,我开始实例化。 但似乎没有任何事情发生。 当前服务器没有响应

是否有人熟悉SAP和代理?

这里的服务器:

package leapmotiongesten;

import java.io.IOException;
import java.net.*;

public class UDPServer
{
    public static void main( String[] args ) throws IOException
    {
        DatagramSocket socket = new DatagramSocket( 6767 );

        while ( true )
        {
            DatagramPacket packet = new DatagramPacket( new byte[1024], 1024 );
            socket.receive( packet );
            InetAddress address = packet.getAddress();
            int         port    = packet.getPort();
            int         len     = packet.getLength();
            byte[]      data    = packet.getData();

            System.out.printf( "Anfrage von %s vom Port %d mit der Länge %d:%n%s%n",
                               address, port, len, new String( data, 0, len ) );
        }
    }
}

0 个答案:

没有答案