Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Galera o erro que me retorna no visual studio é esse:
no instance of overloaded function "System::Net::Sockets::Socket::Send" matches the argument list socket2 192 argument types are: (cli::array<unsigned char, 1> ^, int, int, int)
object type is: System::Net::Sockets::Socket
Onde está acontecendo o erro é aqui:
clientSock_cliente->Send(clienteData,0, clienteData->Length, 0);
ó código da minha aplicação:
#pragma once
#include <string>
namespace socket2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Text;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::IO;
// using namespace std;
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::TextBox^ textArquivo;
private: System::Windows::Forms::Button^ btnEnviar;
private: System::Windows::Forms::ListBox^ lbmsgCliente;
private: System::Windows::Forms::PictureBox^ pictureBox1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
this->label1 = (gcnew System::Windows::Forms::Label());
this->textArquivo = (gcnew System::Windows::Forms::TextBox());
this->btnEnviar = (gcnew System::Windows::Forms::Button());
this->lbmsgCliente = (gcnew System::Windows::Forms::ListBox());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 26);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(210, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Informe local e nome do arquivo a transferir";
//
// textArquivo
//
this->textArquivo->Location = System::Drawing::Point(12, 52);
this->textArquivo->Name = L"textArquivo";
this->textArquivo->Size = System::Drawing::Size(237, 20);
this->textArquivo->TabIndex = 1;
//
// btnEnviar
//
this->btnEnviar->Location = System::Drawing::Point(12, 78);
this->btnEnviar->Name = L"btnEnviar";
this->btnEnviar->Size = System::Drawing::Size(237, 23);
this->btnEnviar->TabIndex = 2;
this->btnEnviar->Text = L"Conecata com o servidor e trafere arquivo";
this->btnEnviar->UseVisualStyleBackColor = true;
this->btnEnviar->Click += gcnew System::EventHandler(this, &MyForm::btnEnviar_Click);
//
// lbmsgCliente
//
this->lbmsgCliente->FormattingEnabled = true;
this->lbmsgCliente->Location = System::Drawing::Point(15, 107);
this->lbmsgCliente->Name = L"lbmsgCliente";
this->lbmsgCliente->Size = System::Drawing::Size(234, 173);
this->lbmsgCliente->TabIndex = 3;
//
// pictureBox1
//
this->pictureBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->pictureBox1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pictureBox1.BackgroundImage")));
this->pictureBox1->Location = System::Drawing::Point(268, 52);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(210, 163);
this->pictureBox1->TabIndex = 4;
this->pictureBox1->TabStop = false;
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(553, 303);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->lbmsgCliente);
this->Controls->Add(this->btnEnviar);
this->Controls->Add(this->textArquivo);
this->Controls->Add(this->label1);
this->Name = L"MyForm";
this->Text = L"MyForm";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}private:
static String^ error;
static String^ MessagemClitente;
static String^ EnderecoIp;
static IPEndPoint^ ipEnd_cliente;
static Socket^ clientSock_cliente;
static String^ caminhoArquivo;
static String^ caminhoCompleto;
static String^ nomeArquivo;
//static Byte fileData;
static array<Byte>^ fileData =gcnew array<Byte>(10);
static array<Byte>^ nomeArquivoByte = gcnew array<Byte>(10);
static array<Byte>^ clienteData = gcnew array<Byte>(10);
static array<Byte>^ nomeArquivoLem= gcnew array<Byte>(10);
static void enviarArquivo(String^ enviarArquivo) {
try {
EnderecoIp = "192.168.1.11";
ipEnd_cliente = gcnew IPEndPoint(IPAddress::Parse(EnderecoIp),5656);
clientSock_cliente = gcnew Socket(AddressFamily::InterNetwork,SocketType::Stream,ProtocolType::IP);
caminhoArquivo = "";
nomeArquivo = nomeArquivo->Replace("\\","/");
while (nomeArquivo->IndexOf("/")>-1) {
caminhoArquivo += nomeArquivo->Substring(0, nomeArquivo->IndexOf("/") + 1);
nomeArquivo = nomeArquivo->Substring(nomeArquivo->IndexOf("/")+1);
}
nomeArquivoByte = Encoding::UTF8->GetBytes(nomeArquivo);
if (nomeArquivoByte->Length>5000*1024) {
MessagemClitente = "O tamanho do arquivo é maior que 5MB, tente um arquivo menor";
}
caminhoCompleto = caminhoArquivo + nomeArquivo;
fileData= File::ReadAllBytes(caminhoArquivo);
clienteData = gcnew array<Byte>(10) { 4 + nomeArquivoByte->Length + fileData->Length };
nomeArquivoLem =BitConverter::GetBytes(nomeArquivoByte->Length);
nomeArquivoLem->CopyTo(clienteData,0);
nomeArquivoByte->CopyTo(clienteData, 4);
fileData->CopyTo(clienteData,4 + nomeArquivoByte->Length);
clientSock_cliente->Connect(ipEnd_cliente);
clientSock_cliente->Send(clienteData,0, clienteData->Length, 0);
clientSock_cliente->Close();
}
catch (...) {
}
}
private: System::Void btnEnviar_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
Por favor me ajudem a soluciona esse problema já to 2 dias quebrando a cabeça mais nenhuma solução.
Carregando comentários...