使用 VB 2008 的在线聊天应用程序,使用 TCP 或 UDP 套接字
我想开发一个具有服务器/客户端模型的聊天应用程序,在 VISUAL BASIC 2008 中打开 TCP 或 UDP 套接字。是否有一个可以下载的工作示例,或者一些代码来帮助我完成这个项目?
提前致谢。
编辑:谢谢您的回答,真的非常感谢。但我堆栈在某个地方,因为我的应用程序只能在本地运行,而不能在整个互联网上运行。
我在服务器部分的代码如下:
在此处输入代码 readData = "已连接到聊天服务器 ..." LabelConnection.Text = "已连接" PictureBox1.Image = My.Resources.Globe_Connected_Icon_39x33 PictureBox1.BackColor = Color.Transparent msg() clientSocket.Connect("127.0.0.1", 8888) 在此处输入代码
现在,我应该放置一些变量或其他内容来保留目标计算机的 IP 地址,而不是 127.0.0.1?我该怎么做呢?有人可以帮忙吗?
I want to develop a chat application with a server/client model, opening TCP or UDP sockets in VISUAL BASIC 2008. Is there a working example I can download, or some code to help me with this project?
Thanks in advance.
Edit: Thanks for the answer, really really appreciate it. But im stack somewhere, because my application will work only locally, but not throughout the Internet.
My code on the server part is the following:
enter code here readData = "Conected to Chat Server ..." LabelConnection.Text = "Connected" PictureBox1.Image = My.Resources.Globe_Connected_Icon_39x33 PictureBox1.BackColor = Color.Transparent msg() clientSocket.Connect("127.0.0.1", 8888) enter code here
Now, instead of 127.0.0.1 I should put some variable or something that keeps the IP address of the target machine? How would I do that? Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本质上,您需要构建一个聊天服务器应用程序和一个连接到服务器并启动数据交换的客户端程序。为了真正使这项工作正常进行,您还必须学习一些有关线程的知识,以便您的客户端/侦听器异步运行。
以下是可供查看的示例项目列表:
Wintalk(Microsoft 提供的示例,用于介绍 WinForms、套接字和 .NET Framework)
< a href="http://msdn.microsoft.com/en-us/library/aa478452.aspx" rel="nofollow">创建多用户 TCP 聊天应用程序
TCP/IP 聊天程序
使用 .NET 套接字的简单聊天应用程序
使用异步 TCP 套接字的聊天应用程序
使用 C# 的 TCP/IP 聊天应用程序
VB.NET 套接字客户端类
您可能会发现用 C# 编写的任何内容(如上面的一些示例)都应该相对简单地转换为 VB.NET。如果您需要一些额外的指导,请尝试一些可用的在线转换工具,例如 DeveloperFusion。
最后,MSDN 文档System.Net.Sockets 命名空间(您将广泛使用)的 a> 是一个极好的资源。
Essentially, you'll need to build a chat server application and a client program that connects to the server and initiates the data exchange. To really make this work right, you're also going to have to learn a little bit about threading so that your client/listener runs asynchronously.
Here's a list of sample projects to take a look at:
Wintalk (a Microsoft-provided sample to introduce WinForms, sockets, and the .NET Framework)
Creating a Multi-User TCP Chat Application
A TCP/IP Chat Program
Simple Chat Application Using .NET Sockets
A Chat Application Using Asynchronous TCP Sockets
TCP/IP Chat Application Using C#
VB.NET Sockets Client Class
Anything you might find that is written in C# (like a few of the above samples) should be relatively straightforward to convert to VB.NET. If you need some additional guidance, try some of the available online conversion tools, such as the one provided by DeveloperFusion.
Finally, the MSDN documentation for the
System.Net.Sockets
namespace (which you'll be using extensively) is an excellent resource as you start digging through the sample projects and find yourself with some nagging, unanswered questions.