Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6197575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:50:45+00:00 2026-05-24T03:50:45+00:00

I’m making small program for socket communication in C#. Here’re my codes: Client (data

  • 0

I’m making small program for socket communication in C#. Here’re my codes:
Client (data sender):

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();
    }
}
}

Server (data reciver):

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<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


    }
}

}
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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:50:46+00:00Added an answer on May 24, 2026 at 3:50 am

    You’re listening on port 80, that is the port your client program should connect to. The “1234” is the LOCAL port the server is bound to. Nothing is listening on that port.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.