Note that there are some explanatory texts on larger screens.

plurals
  1. POSocket communication error
    primarykey
    data
    text
    <p>I'm making small program for socket communication in C#. Here're my codes: Client (data sender):</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; namespace Client { class Program { static Socket sck; //vytvor socket static void Main(string[] args) { sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234); //nastav premennú loacalEndPoint na lokálnu ip a port 1234 try //Skús sa { sck.Connect(localEndPoint); // pripojiť } catch { //ak sa to nepodarí Console.Write("Unable to connect to remote ip end point \r\n"); //vypíš chybovú hlášku Main(args); } Console.Write("Enter text: "); string text = Console.ReadLine(); byte[] data = Encoding.ASCII.GetBytes(text); sck.Send(data); Console.Write("Data sent!\r\n"); Console.Write("Press any key to continue..."); Console.Read(); sck.Close(); } } } </code></pre> <p>Server (data reciver):</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; namespace Server { class Program { static byte[] Buffer { get; set; } //vytvor Buffer static Socket sck; static void Main(string[] args) { sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //vytvor Socket sck.Bind(new IPEndPoint(0, 1234)); sck.Listen(80); Socket accepted = sck.Accept(); Buffer = new byte[accepted.SendBufferSize]; int bytesRead = accepted.Receive(Buffer); byte[] formatted = new byte[bytesRead]; //vytvor novú Array a jej dĺžka bude dĺžka priatých infomácii for(int i=0; i&lt;bytesRead;i++){ formatted[i] = Buffer[i]; //načítaj z Buffer do formatted všetky priate Bajty } string strData = Encoding.ASCII.GetString(formatted); //z ASCII hodnôt urob reťazec Console.Write(strData + "\r\n"); //vypíš data sck.Close(); //ukonči spojenie } } </code></pre> <p>} My problem is: In client program I'm sending data on port 1234 to local ip. But I cannot connect. I have tried port 80 and it has connected. So please, where's my problem? How can I connect to everyone port? Please ignore comments in code and please help me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload