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

  • Home
  • SEARCH
  • 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 6832267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:50:17+00:00 2026-05-26T22:50:17+00:00

I am rather new to socket programming but here goes nothing. I have been

  • 0

I am rather new to socket programming but here goes nothing.

I have been trying to do some simple TCP communications between a C# server and a PHP client. However, I have had no luck in getting a connection between them. I am basically sending a desktop application messages through the web browser via PHP socket communication. However, I keep getting a timeout error.

My code is the following:

My C# Server code – It simply listens and notifies me if a connection is made

    static void Main(string[] args)
    {
        try
        {
            IPAddress localAddress = IPAddress.Parse("xx.xx.xx.xx");

            TcpListener listener = new TcpListener(localAddress, 4761);

            listener.Start(1);

            while (true)
            {
                Console.WriteLine("Server is waiting on socket {0}", listener.LocalEndpoint);

                TcpClient client = listener.AcceptTcpClient();

                NetworkStream IO = client.GetStream();

                Console.WriteLine("Recieved a connection from {0}", client.Client.RemoteEndPoint);

                Console.WriteLine("Time to depart.");
                client.Close();
            }
        }
        catch (Exception E)
        {
            Console.WriteLine("Caught exception: {0}", E.ToString());
        }
   }

PHP Client – This is a function I made that simply connects to the server (failing miserably)

            public function Hook_Up($Host_IP)
    {
        $this->String_and_Cup = fsockopen("xx.xx.xx.xx", 4761);

        if($this->String_and_Cup)
        {
            echo "Congratulations, it's a socket connection...";
        }
        else
        {
            echo "I'm sorry, the socket connection didn't make it...";
        }
    }

All I want to do so far is connect to this server through the browser. I’d appreciate the input on how to do so.

Thanks in advance.

  • 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-26T22:50:18+00:00Added an answer on May 26, 2026 at 10:50 pm

    I dont think what you are trying to achieve should be done this way. You will not be able to connect to a tcp port over the http which is the protocol the browser uses. The PHP socket you created must be run from the command line in order for it to work correctly.

    From what is can tell you, you might wanna have a look at the web sockets which is an html5 implementation which is currently supported by newer versions of chrome and firefox. The web sockets uses a web socket protocol to implement push based systems where you can have a server that uses a memory queue such as an active mq to push the messages from the server and the client which is the browser should subscrbe to these messages from the server over the queue.

    TCP sockets are not meant for browsers. If how ever you wanna connect to a tcp socket from server you can do it just using javascript as given here http://ajaxian.com/archives/tcpsocket-sockets-in-the-browser

    var conn = new TCPSocket(hostname, port)
    
    conn.onopen = function() { alert('connection opened!') }
    conn.onread = function(data) { alert('RECEIVE: ' + data) }
    conn.onclose = function(data) { alert('connection closed!') }
    
    conn.send('Hello World');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im rather new to python but I have been attemping to learn the basics.
Rather new to REST and Jersey, and I'm trying out some basic examples. I've
I am a rather new C++ programmer. I have made a very simple game
I am trying to hit a webserver using a simple Socket rather than using
I'm rather new to Ant but I have experienced it's quite good pattern to
I'm rather new to jQuery and I'm trying to make a cool little menu
I'm rather new to Django and I'm using Django 1.0. I have this: forms.py:
I am rather new to Linux device driver programmring, but for debugging purposes, I
I am rather new to VIM. I got some source code and this is
I'm rather new to JAXB and have come across a problem which I can't

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.