Home > Backend Development > C#.Net Tutorial > 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.

黄舟
Release: 2017-03-10 14:05:55
Original
1363 people have browsed it

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";
        }
    }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template