• 大小: 0.19M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: 其他
  • 标签: 其他  

资源简介

即时通信.zip

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace New_QQ
{
    public partial class Form1 : Form
    {
        private static IPAddress clientIP;
        public static IPEndPoint clientIPEndPoint;
        private static UdpClient receiveUdpClient;
        private static IPEndPoint remoteIpEndPoint;
        private static IPEndPoint serverIpEndPoint;
        private static TcpClient tcpClient;
        public static UdpClient sendUdpClient;
        public static UdpClient chatClient;
        private static string userListstring;
        private static BinaryReader binaryReader;
        private static NetworkStream networkStream;
        private static Thread receiveThread;
        private static Thread sendThread;
        public Form1()
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            //创建接受套接字
            clientIP = IPAddress.Parse(txtLocalIP.Text);
            clientIPEndPoint = new IPEndPoint(clientIP int.Parse(txtlocalport.Text));
            serverIpEndPoint=new IPEndPoint(IPAddress.Parse(txtserverIP.Text)int.Parse(txtServerPort.Text) );
            receiveUdpClient = new UdpClient(clientIPEndPoint);
            //启动接受线程
            receiveThread = new Thread(ReceiveMessage);
            receiveThread.Start();
            //匿名发送
            sendUdpClient = new UdpClient(0);
            //启动发送线程
            sendThread = new Thread(SendMessage);
            sendThread.Start(string.Format(“login{0}{1}“ txtusername.Text clientIPEndPoint));
            button1.Enabled = false;
            this.Text = txtusername.Text;
            button2.Enabled = true;
            this.ControlBox = false;
        }

        private void ReceiveMessage()
        {
            remoteIpEndPoint = new IPEndPoint(IPAddress.Any 0);
            while (true)
            {
                try
                {
                    //关闭receiveUdpClient时会产生异常
                    byte[] receiveBytes = receiveUdpClient.Receive(ref remoteIpEndPoint);
                    string message = Encoding.Unicode.GetString(receiveBytes 0 receiveBytes.Length);
                    //处理消息
                    string[] splitstring = message.Split(‘‘);
                    switch (splitstring[0])
                    {
                        case “Accept“:
                            try
                            {
                                tcpClient = new TcpClient();
                                tcpClient.Connect(remoteIpEndPoint.Address int.Parse(txtServerPort.Text));
                      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        187  2016-11-10 21:22  New QQ\App.config

     文件      12800  2016-11-11 21:57  New QQ\bin\Debug\New QQ.exe

     文件        187  2016-11-10 21:22  New QQ\bin\Debug\New QQ.exe.config

     文件      26112  2016-11-11 21:57  New QQ\bin\Debug\New QQ.pdb

     文件      23168  2016-11-11 21:58  New QQ\bin\Debug\New QQ.vshost.exe

     文件        187  2016-11-10 21:22  New QQ\bin\Debug\New QQ.vshost.exe.config

     文件        490  2010-03-17 22:39  New QQ\bin\Debug\New QQ.vshost.exe.manifest

     文件       6005  2016-11-11 21:57  New QQ\Form1.cs

     文件       8431  2016-11-11 21:57  New QQ\Form1.Designer.cs

     文件       5817  2016-11-11 21:57  New QQ\Form1.resx

     文件       3792  2016-11-10 22:25  New QQ\New QQ.csproj

     文件       1453  2016-11-11 21:01  New QQ\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6923  2016-11-10 21:32  New QQ\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        573  2016-11-11 22:08  New QQ\obj\Debug\New QQ.csproj.FileListAbsolute.txt

     文件        977  2016-11-11 21:57  New QQ\obj\Debug\New QQ.csproj.GenerateResource.Cache

     文件       2211  2016-11-10 22:25  New QQ\obj\Debug\New QQ.csprojResolveAssemblyReference.cache

     文件      12800  2016-11-11 21:57  New QQ\obj\Debug\New QQ.exe

     文件      26112  2016-11-11 21:57  New QQ\obj\Debug\New QQ.pdb

     文件        180  2016-11-11 21:57  New QQ\obj\Debug\New_QQ.Form1.resources

     文件        180  2016-11-10 22:25  New QQ\obj\Debug\New_QQ.Properties.Resources.resources

     文件          0  2016-11-10 21:23  New QQ\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2016-11-10 21:23  New QQ\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2016-11-10 21:23  New QQ\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件        529  2016-11-10 21:23  New QQ\Program.cs

     文件       1442  2016-11-10 21:23  New QQ\Properties\AssemblyInfo.cs

     文件       2842  2016-11-10 21:23  New QQ\Properties\Resources.Designer.cs

     文件       5612  2016-11-10 21:22  New QQ\Properties\Resources.resx

     文件       1093  2016-11-10 21:23  New QQ\Properties\Settings.Designer.cs

     文件        249  2016-11-10 21:22  New QQ\Properties\Settings.settings

     目录          0  2016-11-10 21:23  New QQ\obj\Debug\TempPE

............此处省略10个文件信息

评论

共有 条评论