using System; using System.Web; using AspxServer; public partial class AspxService : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { AspxServer.HeartBeatToMainServer(); //.... } }
using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Net.Sockets; namespace AspxServer { public class ASocket { private static ASocket _theSocket = new ASocket(); public static HeartBeatToMainServer() { _theSocket.SendBeartBeat(); } private void SendHeartBeat() { byte[] sendBuf = BitConverter.GetBytes((UInt16) 1000); _sockObj.Send(sendBuf, 2); } private UdpClient _sockObj = null; public ASocket() { try {// Create the socket and set remote server on localhost port 1001 _sockObj = new UdpClient("localhost", 1001); _sockObj.BeginReceive(ReceiveCallback, null); } catch (Exception ex){ } } private void ReceiveCallback(IAsyncResult res) { IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0); byte[] dataBytes = _aSocket.EndReceive(res, ref remoteEP); //.... _sockObj.BeginReceive(ReceiveCallback, null); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)