簡體   English   中英

我的發送功能(socket庫:system.net和system.net.sockets)有一些錯誤

[英]my send function(socket librarys:system.net & system.net.sockets) has some errors

我正在用C#編寫客戶端/服務器應用程序

我的代碼:

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


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {   }

        private void button1_Click(object sender, EventArgs e)
        {
            ///openfile
            OpenFileDialog file = new OpenFileDialog();
            if (file.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = file.FileName;
            }
        }

        private void label2_Click(object sender, EventArgs e)
        {   }

        private void label3_Click(object sender, EventArgs e)
        {   }

        private void button2_Click(object sender, EventArgs e)
        {
            //Socket send = new Socket(addressFamily.internetwork,                                    
            socketType.stream, protocolType.tcp);
            Socket send = new Socket(AddressFamily.InterNetwork,                                    
            SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint port = new 
            IPEndPoint(IPAddress.Parse(ip.Text),int.Parse(Port.Text));
            send.Send(port);
        }

        private void Form1_Load(object sender, EventArgs e)
        {   }

        private void label4_Click(object sender, EventArgs e)
        {   }

        private void label3_Click_1(object sender, EventArgs e)
        {   }
    }
}

我的錯誤是:

錯誤2最好的重載方法匹配System.Net.Sockets.Socket.Send(System.Collections.Generic.IList>)'有一些無效的參數C:\\ Users \\ Acer \\ AppData \\ Local \\ Temporary Projects \\ WindowsFormsApplication1 \\ Form1.cs 53 13 WindowsFormsApplication1

和錯誤3參數1:無法從'System.Net.IPEndPoint'轉換為'System.Collections.Generic.IList>'C:\\ Users \\ Acer \\ AppData \\ Local \\ Temporary Projects \\ WindowsFormsApplication1 \\ Form1.cs 53 23 WindowsFormsApplication1

IpEndPoint不屬於Send方法。 此方法希望傳輸數據。 EndPoint屬於Connect方法。

因此,您的錯誤消息。

您肯定要先連接,然后再嘗試發送數據:

send.Connect(port);

圖片或每個文件

如果您想通過套接字發送圖片,則應該看一下這篇文章

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM