怎样用C实现局域网通信...

hackyxd 2007-10-11 10:42:13
甲和乙在学校机房一起上课,属于同一个局域网,且没有广域网.
甲想给乙发消息,但是不能动乙的机器,怎样用C实现甲給乙发消息呢..
XP SP2的机子.
(不能用XP自带的信使服务.)
如果不能用C的话,VB也行啊..
...全文
256 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
星羽怎么什么代码都有啊
星羽 2007-10-12
  • 打赏
  • 举报
回复


#define _UNICODE
#define UNICODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <windows.h>
#include <locale.h>
#include <lm.h>
#pragma comment(lib,"netapi32.lib")
int wmain(int argc, wchar_t *argv[])
{
 int count;
 wchar_t *wdest, *wfrom, *buffer,*wtarget;
 DWORD dwReturn;
 if((argc <4) || (argc >5))
 {
  printf("Usge: %S <DestIP> <SourIP> <Message> [Count]\n",argv[0]);
  printf("Count: Count means number of times to send message,default is 1.\n");
  return 0;
 }
 wdest = argv[1]; //目标计算机
 wfrom = argv[2]; //源计算机
 buffer = argv[3]; //发送的信息
 count = _wtoi(argv[4]); //发送次数,缺省为1次
 if(count ==0)
  count = 1;
  printf("count = %d\n",count);
 dwReturn = NetMessageBufferSend(NULL, wdest, wfrom,
    (LPBYTE)buffer, 2*lstrlen(buffer)); //因为buffer是Unicode编码,所以需要乘以2
 if(dwReturn == NERR_Success)
 {
  printf("Send OK!");
  while(count-->1)
  {
   NetMessageBufferSend(NULL, wtarget, wfrom, (LPBYTE)buffe,2*lstrlen(buffer));
  }
  return 0;
 }
 if(dwReturn == NERR_NameNotFound)
 {
  printf("The user name could not be found.\n");
  return 0;
 }
 if(dwReturn == NERR_NetworkError)
 {
  printf("A general failure occurred in the network hardware.\n");
  return 0;
 }
 if(dwReturn == ERROR_NOT_SUPPORTED)
 {
  printf("This network request is not supported.\n");
  return 0;
 }
 if(dwReturn == ERROR_INVALID_PARAMETER)
 {
  printf("The specified parameter is invalid.\n");
  return 0;
 }
 if(dwReturn == ERROR_ACCESS_DENIED)
 {
  printf("The user does not have access to the requested information.\n");
  return 0;
 }
 else
  printf("Unknown error!\n");
  return 0;
}

  

ckt 2007-10-11
  • 打赏
  • 举报
回复
socket 百度或者google搜索下
fengdream 2007-10-11
  • 打赏
  • 举报
回复
理论上是完全可以实现的,调用相应接口,报文就通过通过tcp/ip协议一层层的下发了。但是发送后对方需要通过tcp/ip协议接受并显示。
即需要运行一个类似qq的应用程序,能实现收发和相应的界面。
所以,可以搜索一下socket编程类似。

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧