如何使用Winsock制作C#聊天应用程序? [英] How to make a C# chat application using winsock?

查看:60
本文介绍了如何使用Winsock制作C#聊天应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过在互联网上阅读一些教程,但是对我来说它们太复杂了(我只有14岁),但是我从中得到了一些东西.据我所知:

I've tried reading some of the tutorials on the internet, but they're too complicated for me (I'm just 14) but I got a few things from them though. This is as far as I got:

int portNumberVariable = 814; string ipAddressVariable = "127.0.0.1"; // Binding server to 127.0.0.1:814 Console.WriteLine("Binding server to " + ipAddressVariable + ":" + portNumberVariable.ToString() + "..."); SocketPermission socketPermission = new SocketPermission(NetworkAccess.Accept, TransportType.Tcp, ipAddress, portNumber); Socket socketListener; IPHostEntry ipHostEntry = Dns.GetHostEntry(ipAddressVariable); IPAddress ipAddress = ipHostEntry.AddressList[0]; IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, portNumberVariable); socketListener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socketListener.Bind(ipEndPoint); // (This part of the code has been removed by me because it is not relevant for this forum question) .... // Start listening for connections socketListener.Listen(15000);

Soo,在使套接字开始监听传入的连接之后,那又如何?我们是否要创建某种客户端连接事件"?我需要像这样:

Soo, after we make the socket start listening for incoming connections, THEN WHAT? Do we create some sort of 'client connect event'? I need it to be like this:

1.服务器启动

2.服务器将套接字绑定到127.0.0.1:814

2. The server binds the socket to 127.0.0.1:814

3.服务器开始在该端口上侦听

3. The server starts listening on that port

4.客户端使用地址和端口连接到服务器(这是一个聊天应用程序,最多15000个客户端)

4. A client connects to the server using the address and port (This is a chat application, 15000 clients max)

5.客户端将其唯一ID"发送到服务器

5. The client sends it's 'unique ID' to the server

6.服务器将唯一ID存储在数组中

6. The unique ID gets stored in an array by the server

7.其余聊天内容代码

7. Rest of the chat stuff codes

推荐答案

iNehMan,

Hi iNehMan,

谢谢您在这里发布.

根据您的问题与WCF更相关,我将其移至 Windows Communication Foundation,序列化和网络论坛以获取适当的支持.

According to your question is more related to WCF, I will move it to Windows Communication Foundation, Serialization, and Networking forum for suitable support.

Visual C#讨论并询问C#编程语言,IDE,库,示例和工具.

The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools.

如果您有一些语法或代码错误,请随时与我们联系.我们将尽力为您提供解决方案.

If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

感谢您的理解与合作.

最好的问候,

温迪


这篇关于如何使用Winsock制作C#聊天应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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