Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
fraggr
unregistriert
So ist es und darum solltest du einfach mal anfangen, anstatt schon um Hilfe zu bitten, bevor du überhaupt eine konkrete Frage hast.ich würde mich immer noch Laie nennen weswegen ich hier im Hilfe und Feedback fragen möchte bevor ich mich an den Code mache. [...] Praktisch glaube ich das ich erstmal auf tausend Probleme treffen werde weil ich viele Dinge noch gar nicht bedacht habe oder es einfach nicht so ist wie ich es mir vorstelle.
Wenn du wie Schorsch schon sagt mit async / multithreaded anfangen möchtest, kannst du dir mal boost/asio anschauen:
http://www.boost.org/doc/libs/1_61_0/doc…boost_asio.html
Ich hab erst in diesem Semester für Verteilte Systeme damit gearbeitet, kanns nur empfehlen
ich würde gerne (auch Berufsbedingt) ein wenig in die Netzwerktechnik in der Programmierung mit C# einsteigen.
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Net.Sockets; using System.Net; using System.Threading; namespace ChatServer { public class Program { static void Main(string[] args) { const int port = 31243; TcpListener listener = null; try { //start listen to Port Console.WriteLine("Start server..."); listener = new TcpListener(IPAddress.Any, port); //Every Computer is allowed listener.Start(); Console.WriteLine("Server started!"); //Buffer for reading data byte[] buffer = new byte[256]; while (true) { //establish connection Console.WriteLine("Listening on port " + port); Console.WriteLine("Waiting for connection..."); TcpClient client = listener.AcceptTcpClient(); Console.WriteLine("Connection Established!"); NetworkStream inOut = client.GetStream(); int i; //Loop to receive data by client while ((i = inOut.Read(buffer, 0, buffer.Length)) != 0) { //convert the data back to string and show it string data = Encoding.ASCII.GetString(buffer, 0, i); Console.WriteLine("Received: " + data + " with " + i + " bytes"); //Write Back the text to the client Console.WriteLine("Sending back: " + data); inOut.Write(buffer, 0, i); } //Close connection client.Close(); Console.WriteLine("Connection closed"); Console.ReadKey(); } } catch (Exception e) { throw new Exception("Error: ", e); //funktioniert nicht } finally { //stop listening for new clients listener.Stop(); } } } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using System.IO; using System.Net; using System.Net.Sockets; using System.Security; using System.Security.Permissions; namespace ChatClient { public class Program { static void Main(string[] args) { TcpClient client = null; try { //type the Server IP Console.WriteLine("Insert IP from Server: "); string ip = Console.ReadLine(); //open connection client = new TcpClient(ip, 31243); NetworkStream inOut = client.GetStream(); while (true) { //read text to send Console.WriteLine("Connection established!"); Console.WriteLine("Something to send to server: "); string eingabe = Console.ReadLine(); //convert and send byte[] bytes = ASCIIEncoding.ASCII.GetBytes(eingabe); Console.WriteLine("Sending..."); inOut.Write(bytes, 0, bytes.Length); //read back byte[] bytesToRead = new byte[client.ReceiveBufferSize]; int answer = inOut.Read(bytesToRead, 0, client.ReceiveBufferSize); //convert and output string answerString = ASCIIEncoding.ASCII.GetString(bytesToRead, 0, answer); Console.WriteLine("From Server: " + answerString); } } catch { Console.WriteLine("Error. Programm wird beendet"); Console.ReadKey(); } finally { client.Close(); } } } } |
Alter Hase
Beruf: Softwareentwickler (aktuell Web/Node); Freiberuflicher Google Proxy
Werbeanzeige