Transmit lots of packets

If you don't have your socket set to non blocking (which means you have to deal with recv() wanting to block when you call it) then using the send() transmitfunction is no problem as it will block until the packet you are sending has gone out.  However if you have O_NONBLOCK non blocking turned on so […]

Read More

FTP File Download

Simple FTP File Download using namespace System::IO; //Used for FTP using namespace System::Net; //Used for FTP array<Byte>^FtpFileData; WebClient^ request = gcnew WebClient; request->Credentials = gcnew NetworkCredential("MyUsername","MyPassword"); try { FtpFileData= request->DownloadData("ftp://1.2.3.4/SomeDirectory/MyFile.csv"); } catch (WebException^ e) { FtpFileData= gcnew array<Byte>(0); }      

Read More

Download File From URL

  private: WebClient ^WebClient1; //******************************* //******************************* //********** FORM LOAD ********** //******************************* //******************************* private: System::Void frmInstallControlCentre_Load(System::Object^ sender, System::EventArgs^ e) { try { //—– CREATE DIRECTORY —– if (!Directory::Exists(TEMP_DOWNLOAD_DIRECTORY)) Directory::CreateDirectory(TEMP_DOWNLOAD_DIRECTORY); //—– DELETE FILE IF IT ALREADY EXISTS —– try { if (File::Exists(TEMP_DOWNLOAD_DIRECTORY + "SomeFile.txt")) { //If file has read only attribute set clear it so that delete […]

Read More

UDP Client Simple Transmit Only

UdpClient^ udpClient1; udpClient1 = gcnew UdpClient; IPAddress ^address; int byteId; array<Byte>^sendBytes = gcnew array<Byte>(1500); try { if (!IPAddress::TryParse(DestIpAddressString, address)) { //Invalid IP Address return; } udpClient1->Connect(address, REMOTE_UDP_SOCKET); byteId = 0; sendBytes[byteId++] = ; … sendBytes[byteId++] = ; //Transmit Packet udpClient1->Send(sendBytes, byteId); udpClient1->Close(); } catch (Exception ^) { }

Read More

UDP Server

In Your .h File #define RECEIVE_BUFFER_SIZE 1500 private: Socket ^serverSocket; //————————————- //—– CLASS FOR RECEIVE SOCKETS —– //————————————- ref class StateObject { public: property int bufSize; property Socket ^workSocket; property array<unsigned char>^ message; StateObject(Socket^ sock, int bufsize) { workSocket = sock; bufSize = bufsize; message = gcnew array<unsigned char>(bufsize); } }; Create Socket //—– SETUP […]

Read More

Setting Special Socket Options

Use SetSocketOption TcpSocket->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::DontLinger, true); TcpSocket->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::ReuseAddress, true);

Read More

Converting IP Addresses

IP Address Text Entry Box You can use a MaskedTextBox with the mask "###.###.###.###" However its often best just to use a standard text box as the masked text box approah creates issues. Note that the Windows network setup IP address box is not based on a standard tool unfortunately. Parsing Removing Leading Zero's IPAddress::TryParse […]

Read More