如何使用vb.net将邮件从一台计算机发送到另一台计算机? [英] How do i send messages from one computer to another using vb.net?

查看:141
本文介绍了如何使用vb.net将邮件从一台计算机发送到另一台计算机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我一直想这样做几年了,令我惊讶的是,没有人能提出一个解决方案...我想编写一个程序(最好在vb.net中)来发送向与我连接到同一网络的另一台计算机(或设备)发送消息.我希望该消息出现在另一台计算机(或设备)的弹出消息框中.同样,如果可以通过某种蓝牙连接来完成,那将是理想的,否则,本地ip连接就可以了.我不知道该怎么做,但是我知道这是可能的,因为我已经看过一些程序了……实际上,我看过一个名为blackrain的程序,该程序无需安装任何其他软件就可以在屏幕上显示消息. ipod触摸屏指示yser怎么做,然后几乎立即将输入的结果显示在计算机屏幕上.我想知道如果有人有任何想法,请问如何分享这些想法!

Ok so i've been wanting to do this for a few years now and it amazes me that no one can come up with a solution... i want to write a program (preferably in vb.net) that can send a message to another computer (or device) that is connected to the same network as me. I want the message to appear on the other computer (or device) in a popup message box. Also, it would be ideal if this could be done through some sort of bluetooth connection, if not then local ip connection will do. I don't know how i would go about doing this but i know it's possible because i've seen some programs do it... in fact i've seen a program called blackrain that without any additional software installed, can display messages on an ipod touch screen to instruct the yser what to do, and then display the results from their input on the computer screen, almost instantly. I would like to know how that works as well if anyone has any thoughts please feel free to share them!

其他详细信息:

  • 我对vb.net,命令行功能和vbscript有很多经验.

  • I have alot of experience with vb.net, command-line functions, and vbscript.

我当前正在运行Windows 7 Professional x64

I am currently running Windows 7 Professional x64

我有一个外部蓝牙迷你适配器.

I have an external bluetooth mini adapter.

我希望(如果可能的话)类似于那些可以让您通过wifi同步控制笔记本电脑光标的ipod/iphone应用程序;从某种意义上讲,它不需要安装程序,也不需要其他软件. (例如:remotepad.ipa)

I would like this to be (if possible) similar to those ipod/iphone apps that let you control your laptop cursor over wifi sync; in the sense that there is no setup required, and no additional software needed. (Example: remotepad.ipa)

消息框的代码应类似于:

The code for the message box would be something like:

ObjClient = New TcpClient("127.0.0.1", 1000)
TcpClient.Start()
Messagebox.Show("Popup Message Here")
TcpClient.Close()

我知道这段代码会在命令提示符下做同样的事情:

I know that this code will do sort of the same thing in the command prompt:

msg * /SERVER:localhost hello 

否则此代码将在命令提示符下执行相同的操作:

or this code will do the same thing in the command prompt:

msg * hello > localhost

但是我想尽可能不使用任何批处理文件来执行此操作,因为我不想在另一端设置任何内容.

But i want to do this without any batch files if possible, because i don't want to have to set up anything on the other end.

谢谢!

可能与套接字或端口有关吗?

Does it have anything to do with Sockets or Ports maybe?

推荐答案

使用TcpClient和相关库绝对是正确的答案.

Using TcpClient and related libraries is definitely the correct answer.

用于将数据写入特定IP/端口的示例代码:

Sample code for writing data to a specific IP/port:

''' <summary>
''' Send data over TCP/IP network
''' </summary>
''' <param name="data">Data string to write</param>
''' <param name="IP">The connected destination TcpClient</param>
Public Sub WriteData(ByVal data As String, ByRef IP As String)
    Console.WriteLine("Sending message """ & data & """ to " & IP)
    Dim client As TcpClient = New TcpClient()
    client.Connect(New IPEndPoint(IPAddress.Parse(IP), My.Settings.CommPort))
    Dim stream As NetworkStream = client.GetStream()
    Dim sendBytes As Byte() = Encoding.ASCII.GetBytes(data)
    stream.Write(sendBytes, 0, sendBytes.Length)
End Sub

使用TcpListener监视传入的数据.

Use TcpListener for watching for incoming data.

http://msdn.microsoft.com/zh-cn/library/system.net.sockets.tcplistener.aspx

为了知道将其发送到哪个IP ...您可以具有要连接到的内部IP列表,或者可以将每台联网计算机订阅"到您的程序中(如果它们静态地托管在一个盒子上).就我的目的而言,当我使用此代码时,主机进程位于一台已知的服务器上.想要接收消息的客户端进程向主机发送一条快速消息,然后主机将记录该IP以供以后发送.

edit: For knowing what IP to send it to... You could either have a list of internal IPs to connect to, or have each networked computer 'subscribe' to your program if it's hosted statically on a box. For my purposes, when I'm using this code, the host process sits on a known server. Client processes that want to receive messages sends a quick message to the host, which will then record the IP to be able to send to later.

获得请求客户端的IP:

Obtaining the IP of a requesting client:

''Given variable m_listener is an active TcpListener...
Dim client As TcpClient = m_listener.AcceptTcpClient()
Dim requesterIP As String = client.Client.RemoteEndPoint.ToString().Split(New Char() {":"})(0)

这篇关于如何使用vb.net将邮件从一台计算机发送到另一台计算机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆