Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Socket File Transfer

Socket File Transfer

Scheduled Pinned Locked Moved Managed C++/CLI
sysadmindata-structuresperformance
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    javad_2005
    wrote on last edited by
    #1

    Server Socket ^s.... FileStream ^fs.. array^data=gcnew array(4096); int len; do { len=fs->Read(data,0,4096); s->Send(data,0,len); } file Send but don't Complete i think socket send byte with Speed and data Replace with data!

    L M 2 Replies Last reply
    0
    • J javad_2005

      Server Socket ^s.... FileStream ^fs.. array^data=gcnew array(4096); int len; do { len=fs->Read(data,0,4096); s->Send(data,0,len); } file Send but don't Complete i think socket send byte with Speed and data Replace with data!

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      javad_2005 wrote:

      file Send but don't Complete

      Send to what? Don't Complete means what?

      javad_2005 wrote:

      i think socket send byte with Speed and data Replace with data!

      I have no idea what that means but it sounds like something I would not believe.

      led mike

      1 Reply Last reply
      0
      • J javad_2005

        Server Socket ^s.... FileStream ^fs.. array^data=gcnew array(4096); int len; do { len=fs->Read(data,0,4096); s->Send(data,0,len); } file Send but don't Complete i think socket send byte with Speed and data Replace with data!

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        None of the Socket::Send() overloads matches your code.  Which one are you using? What type of array is data? Where's the loop logic code? Is the socket blocking or non blocking? You don't check the number of bytes sent?  What if they all don't get sent in one Send() call? Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        L J 2 Replies Last reply
        0
        • M Mark Salsbery

          None of the Socket::Send() overloads matches your code.  Which one are you using? What type of array is data? Where's the loop logic code? Is the socket blocking or non blocking? You don't check the number of bytes sent?  What if they all don't get sent in one Send() call? Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          We are like a double decker Filet-o-Fish in this thread. Do they make one of those?

          led mike

          1 Reply Last reply
          0
          • M Mark Salsbery

            None of the Socket::Send() overloads matches your code.  Which one are you using? What type of array is data? Where's the loop logic code? Is the socket blocking or non blocking? You don't check the number of bytes sent?  What if they all don't get sent in one Send() call? Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            J Offline
            J Offline
            javad_2005
            wrote on last edited by
            #5

            Server Code: enum Command { NULL, Message, CreateFile, WriteFile, Close }; Object ^ RawDeserialize(array<Byte> ^rawdatas, Type ^anytype ) { int rawsize = Marshal::SizeOf(anytype ); if( rawsize > rawdatas->Length ) return nullptr; IntPtr buffer = Marshal::AllocHGlobal( rawsize ); Marshal::Copy( rawdatas, 0, buffer, rawsize ); Object ^retobj = Marshal::PtrToStructure( buffer, anytype ); Marshal::FreeHGlobal( buffer ); return retobj; } ////////////////////////// [StructLayout(LayoutKind::Sequential, Pack=1, CharSet=CharSet::Ansi)] ref struct TcpPacket { [MarshalAs(UnmanagedType::ByValArray,ArraySubType=UnmanagedType::LPWStr,SizeConst=4096)] array<Byte>^data; //////////Packet Buffer Command cmd; /////Command int Length; /////////Data Length public: TcpPacket() { cmd=Command::NULL; data=gcnew array<Byte>(4096); } }; /////////// ref struct ClientInfo { Socket ^socket; array<Byte> ^Buffer; }; /////////// private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Socket ^TcpSocket=gcnew Socket(AddressFamily::InterNetwork,SocketType::Stream,ProtocolType::Tcp); IPEndPoint ^ipEndPoint=gcnew IPEndPoint(IPAddress::Any,5400); TcpSocket->Bind(ipEndPoint); TcpSocket->Listen(0); ///////////////// TcpSocket->BeginAccept(gcnew AsyncCallback(this,&Form1::OnAccept),TcpSocket); } void OnAccept(IAsyncResult ^ar) { ClientInfo ^info=gcnew ClientInfo; Socket ^socket=safe_cast<Socket ^>(ar->AsyncState); Socket ^SockAccept=socket->EndAccept(ar); TcpPacket ^Packet=gcnew TcpPacket; ////New Packet For Get Packet Size int PSize=Marshal::SizeOf(Packet);/////////Get Packet Size info->socket=SockAccept; info->Buffer=gcnew array<Byte>(PSize); SockAccept->BeginReceive(info->Buffer,0,PSize,SocketFlags::None,gcnew AsyncCallback(this,&Form1::OnReceive),info); } void OnReceive(IAsyncResult ^ar) { ClientInfo ^info=safe_cast<ClientInfo ^>(ar->AsyncState); info->socket->EndReceive(ar); ///Deserialize Buffer TcpPacket ^Packet=gcnew TcpPacket; Type ^typeTcpPacket=Type::GetType(String::Format("{0}",Packet)); Packet=(TcpPacket ^)RawDeserialize( info->Buffer,typeTcpPacket); /////////////////////////// ReleasePacket(Packet); int PSize=Marshal::SizeOf(Packet); info->

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups