資源簡(jiǎn)介
c# 實(shí)現(xiàn)的局域網(wǎng)聊天軟件,可發(fā)送表情,文件。 1.參照網(wǎng)上若干局域網(wǎng)聊天軟件編寫而成。 2.發(fā)送消息使用UDP,傳送文件使用TCP 3.用戶上線時(shí),自動(dòng)發(fā)送廣播消息,而后在雙方好友列表里可以互相看見 4.支持更改用戶名 5.默認(rèn)用戶名為機(jī)器名 代碼里注釋寫得很多,初學(xué)TCP和UDP的朋友可以此做參考。 有興趣的朋友可以在此基礎(chǔ)上添加組播,實(shí)現(xiàn)群聊功能。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Net;
using?System.Net.Sockets;
using?System.Threading;
using?System.Windows.Forms;
namespace?FreeChat
{
????class?ClassBoardCast
????{
????????UdpClient?bcUdpClient?=?new?UdpClient();
????????IPEndPoint?bcIPEndPoint?=?new?IPEndPoint(IPAddress.Parse(“255.255.255.255“)?2425);
????????public?string?localIP?=?string.Empty;
????????//獲取本機(jī)IP,如果是vista或windows7,取InterNetwork對(duì)應(yīng)的地址
????????public?void?GetLocalIP()
????????{
????????????try
????????????{
????????????????foreach?(IPAddress?_ipAddress?in?Dns.GetHostEntry(Dns.GetHostName()).AddressList)
????????????????{
????????????????????if?(_ipAddress.AddressFamily.ToString()?==?“InterNetwork“)
????????????????????{
????????????????????????localIP?=?_ipAddress.ToString();
????????????????????????break;
????????????????????}
????????????????????else
????????????????????{
????????????????????????localIP?=?Dns.GetHo
評(píng)論
共有 條評(píng)論