Currently browsing tag

iOS

File Transfer using C# .Net Socket Programming 3/3

Continued code… Server Code: [C#] using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Net.Sockets; using System.IO; namespace beginSocketServer { //FILE TRANSFER USING C#.NET SOCKET PROGRAMMING – SERVER class Program { static void Main(string[] args) { try { Console.WriteLine(“That program can transfer small file. I’ve test up to 850kb file”); …

Send File from Server to Client using C# Socket Programming 5/6

Full codes are here…   Client code: using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Net.Sockets; using System.IO; namespace Client_Socket { //FILE TRANSFER USING C#.NET SOCKET – CLIENT class Program { static void Main(string[] args) { try { Console.WriteLine(“That program can transfer small file. I’ve test up to 850kb …

Send File from Server to Client using C# Socket Programming 4/6

6) Client Action: This section of code is retrieving file name length and by using this file name which was sent by server at the starting of file data. This will require retrieving file name. int fileNameLen = BitConverter.ToInt32(clientData, 0); string fileName = Encoding.ASCII.GetString(clientData, 4, fileNameLen); 7) Client Action: Now received data is saving at …

Send File from Server to Client using C# Socket Programming 3/6

4) Server Action: These codes are not directly related with socket programming. This is using to read and send file to client. string fileName = “test.txt”;// “Your File Name”; string filePath = @”C:\FT\”;//Your File Path; byte[] fileNameByte = Encoding.ASCII.GetBytes(fileName); byte[] fileData = File.ReadAllBytes(filePath + fileName); byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length]; byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length); fileNameLen.CopyTo(clientData, …

Send File from Server to Client using C# Socket Programming 2/6

2) Client Action: Now turn is coming to client to request server. IPAddress[] ipAddress = Dns.GetHostAddresses(“localhost”); IPEndPoint ipEnd = new IPEndPoint(ipAddress[0], 5656); Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); clientSock.Connect(ipEnd); These codes are from client application, here first two lines are using to get Localhost IP address and by using …