首頁  >  文章  >  後端開發  >  通達OA 使用C#的Socket程式來其取代原有操作的範例程式碼分享

通達OA 使用C#的Socket程式來其取代原有操作的範例程式碼分享

黄舟
黄舟原創
2017-03-10 14:05:551285瀏覽

在通達OA中採用了PHP的語言來進行編程,同樣對於IM的有些操作則採用了Socket的方式進行通訊。最近做的一個程式需要採用C#來做,裡面牽涉到這塊,採用C#進行了重寫,具體還需要進一步進行測試效果。

using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace monitorFlowworkAndSubmit.DAL
{
    class SendSocket
    {
        string MYOA_TDIM_ADDR = "127.0.0.1";
        int MYOA_TDIM_PORT = xxxx;

        public string Send()
        {
            string rst = "";
            
            IPAddress ip = IPAddress.Parse(MYOA_TDIM_ADDR);
            Socket clientSocket = new Socket(AddressFamily.InterNetwork, 
                                        SocketType.Dgram,ProtocolType.Udp);
            try
            {
                clientSocket.Connect(new IPEndPoint(ip, MYOA_TDIM_PORT)); 
                Console.WriteLine("conn OK");
            }
            catch (Exception ex)
            {
                rst = "conn err!";
                return ex.ToString();
            }
            try
            {
                 string sendMessage = "x^a^admin";
                 clientSocket.Send(Encoding.ASCII.GetBytes(sendMessage));                
            }
            catch
            {
                 clientSocket.Shutdown(SocketShutdown.Both);
                 clientSocket.Close();
                 return "send error";
            }
            return "OK";
        }
    }
}

以上是通達OA 使用C#的Socket程式來其取代原有操作的範例程式碼分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn