Hi. I have this connection code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace ConnApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234);
            try
            {
                sck.Connect(ip);
                Console.WriteLine("Connected!");
            }
            catch 
            {
                Console.WriteLine("Error!");
            }
            Console.Read();
        }
    }
}

It's telling me "Error!" and I cannot connect to local. But connection works on port 80. Please help me.

We need a lot more information than "it's telling me Error". What error, exactly, is it giving. What line, exactly, is the error occuring. You should catch specific exceptions, not the generic "catch" you are using. You don't even bother to get the exception object so you can see more information about the problem!

My error response, what I typed it in code - try catch.

I know, but that tells us nothing except there is an exception. Change your catch statement (and following code) to:

catch (Exception ex) {
    Console.WriteLine(ex.Message);
    if (ex.InnerException != null) {
        Console.WriteLine(ex.InnerException.Message);
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.