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 9046915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:46:24+00:00 2026-06-16T11:46:24+00:00

In the server side, i use this code : ServerSocket server = new ServerSocket(1234);

  • 0

In the server side, i use this code :

ServerSocket server = new ServerSocket(1234);
Socket server_socket = server.accept();

I found the server is listening on port 1234.

When one or more client sockets are connected, they are all using the same port 1234 !

That is really confusing :

enter image description here

I remember that multi sockets can’t use the same port, isn’t it right ? Thanks.

  • 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-06-16T11:46:24+00:00Added an answer on June 16, 2026 at 11:46 am

    A TCP connection is identified by four numbers:

    • client (or peer 1) IP
    • server (or peer 2) IP
    • client port
    • server port

    A typical TCP connection is open as follows:

    • The client IP is given by the client’s ISP or NAT.
    • The server IP is given by the user or looked up in a DNS.
    • The client chooses a port arbitrarily from the unassigned range (while avoiding duplicate quadruples)
    • The server port is given by the protocol or explicitly.

    The port that you specify in the ServerSocket is the one the clients connect to. It’s nothing more than a port number that the OS knows that belongs to your application and an object that passes the events from the OS to your application.

    The ServerSocket#accept method returns a Socket. A Socket is an object that wraps a single TCP connection. That is, the client IP, the server IP, the client TCP port and the server TCP port (and some methods to pass the associated data around)

    The first TCP packet that the client sends must contain the server port that your app listens on, otherwise the operating system wouldn’t know what application the connection belongs to.

    Further on, there is no incentive to switch the server TCP port to another number. It doesn’t help the server machine OR the client machine, it needs some overhead to perform (you need to send the new and the old TCP port together), and there’s additional overhead, since the server OS can no longer identify the application by a single port – it needs to associate the application with all server ports it uses (the clients still needs to do it, but a typical client has less connections than a typical server)


    What you see is

    • two inbound connections, belonging to the server (local port:1234). Each has its own Socket in the server application.
    • two outbound connections, belonging to the client (remote port:1234). Each has its own Socket in the client application.
    • one listening connection, belonging to the server. This corresponds to the single ServerSocket that accepts connections.

    Since they are loopback connections, you can see both endpoints mixed together on a single machine. You can also see two distinct client ports (52506 and 52511), both on the local side and on the remote side.

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

Sidebar

Related Questions

Creating a server-side socket will fail if I'm trying to use the same port
I am not sure how to use a single port at server side simultaneously
If I use this code on my aspx page: <asp:BulletedList ID=listClientContacts runat=server> <asp:ListItem><b>My Name</b></asp:ListItem>
Hi i need send file to server i use this code public void PostFile()
This is my server side code or android side code. This code is working
I am trying to use this simple code in WCF: Client Side: ServiceContractClient proxy
I have an issue with Mozilla, i use this client side JavaScript code in
Say,how to implement these three steps: 1.fetch a html source from server side 2.use
Can I use the reverse geocoding server side, e.g. with a C# or C++?
i have a rhel 4 server and use php as a server side scripting

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.