Bestcomy.net blog

Coding for funny

导航

在Web上使用信使服务

Posted on 2004-06-02 18:47  bestcomy  阅读(10682)  评论(17编辑  收藏  举报

前段时间开发一个Web项目,客户要求有即时消息提示功能:
1. 客户端不能安装软件;
2. 客户端不需要打开网页就可以收到即时消息
3. 无论客户端在使用任何软件的时候即时消息都要能被客户马上看到
考虑到客户的网络环境是简单的对等网,通过工作组来分配单位的各个部门,因此采用即时消息服务来解决。
以下是代码,望大家提供意见和建议

using System;
using System.Runtime.InteropServices;

namespace test
{
 /// <summary>
 /// NetSend 的摘要说明。
 /// </summary>
 public class NetSend
 {
  public NetSend()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }

  public int SendMessage(string sFrom,string sTo,string sMessage)
  {
   byte[] bBuffer = System.Text.Encoding.Unicode.GetBytes(sMessage);
   int nRet = NetMessageBufferSend(null,sTo,null,sMessage,sMessage.Length*2+2);
   return nRet;
  }

  [DllImport ("Netapi32", CharSet=CharSet.Unicode)]
  public static extern int NetMessageBufferSend( string servername, string msgname, string fromname, string buf, int buflen);
 }
}

补充NET SEND的语法:
NET SEND {name | * | /DOMAIN[:name] | /USERS} message