Home  >  Article  >  Backend Development  >  Tongda OA uses C# Socket programming to share sample code to replace the original operation.

Tongda OA uses C# Socket programming to share sample code to replace the original operation.

黄舟
黄舟Original
2017-03-10 14:05:551286browse

Tongda OA uses PHP language for programming, and also uses Socket for communication for some operations of IM. A program I recently made needs to be done in C#, which involves this aspect and was rewritten in C#. The specific effect needs to be further tested.

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";
        }
    }
}

The above is the detailed content of Tongda OA uses C# Socket programming to share sample code to replace the original operation.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn