} } HTML Video embed

INFO:

INTER-AUTO doo BiH

INTER AUTOMOBILE GmbH DEUTSCHLAND


PROGRAMMING

Implementation of singly linked list in C# using only one class.

The following program is an attempt at implementing a simple, easy to-understand singly linked list in C#. Many great programs implement a singly linked list in C#. But what all of them have in common is the fact that they all use more than one class which is fine, but I wanted to challenge myself to make a singly linked list that uses only one class and I also wanted to make it extremly simple so that everyone can understand it and learn from it. The code: using System; public class singleLinked { public string data; singleLinked next; singleLinked head; public static void Main() { singleLinked list = new singleLinked(); list.Add("Node 1"); list.Add("Node 2"); list.Add("Node 3"); list.Add("Node 4"); list.Print(); } public void Add(string data) { singleLinked newNode = new singleLinked(); newNode.data = data; newNode.next = head; head = newNode; } public void Print() { singleLinked currentNode = head; while (currentNode != null) { Console.WriteLine(currentNode.data); currentNode = currentNode.next; } } }

Simple TCP server/client in C#

This is a very basic TCP server/client written in C# using sockets. The server and client use the localhost IP address. Alternatively, you can use something such as: public static var DNS = Dns.GetHostEntry("example").AddressList[0]; to get the IP of a website (webserver). Keep in mind that servers can have multiple IP's so sometimes you may need to choose a different one from the address list. The server: using System; using System.Net; using System.Net.Sockets; using System.Text; namespace TCP_server_client_using_Sockets; public static class Program { public static IPAddress address = IPAddress.Parse("127.0.0.1"); public static int port = 1235; public static IPEndPoint endPoint = new(address, port); public static void Main() { Server(); } public static void Server() { Socket listener = new(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); listener.Bind(endPoint); listener.Listen(10); var serverByte = new byte[1024]; var handler = listener.Accept(); Console.WriteLine("Enter a message for the client."); while (true) { var AbortKey = Console.ReadKey(true).Key; if (AbortKey != ConsoleKey.Escape) { var serverReceive = handler.Receive(serverByte, SocketFlags.None); var serverMessage = Encoding.UTF8.GetString(serverByte, 0, serverReceive); Console.WriteLine(serverMessage); var ackM = Console.ReadLine(); var echoAckm = Encoding.UTF8.GetBytes(ackM); var sendAckm = handler.Send(echoAckm, 0); } else { return; } } } } The client: using System; using System.Net; using System.Net.Sockets; using System.Text; namespace TCP_server_client_using_Sockets; public static class Program { public static IPAddress address = IPAddress.Parse("127.0.0.1"); public static int port = 1235; public static IPEndPoint endPoint = new(address, port); public static void Main() { Client(); } public static void Client() { Console.WriteLine("Waiting for connection."); Socket socket = new(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.Connect(endPoint); if (socket.Connected) { Console.WriteLine("Connected"); } else { Console.WriteLine("Not connected"); } Console.WriteLine("Enter a message for the server."); while (true) { var AbortKey = Console.ReadKey(true).Key; if (AbortKey != ConsoleKey.Escape) { var sendMessage = Console.ReadLine(); var byteMessage = Encoding.UTF8.GetBytes(sendMessage); var sMessage = socket.SendAsync(byteMessage, SocketFlags.None); var buffer = new byte[1024]; var receiveMessage = socket.Receive(buffer); var result = Encoding.UTF8.GetString(buffer, 0, receiveMessage); Console.WriteLine(result); } else { return; } } } }