PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 21, 2022

[FIXED] What is socket bind and how to bind an address?

 October 21, 2022     java, networking, sockets     No comments   

Issue

In Java, I need to know what is the bind operation:

ServerSocket.bind()

From Javadoc:

Binds the ServerSocket to a specific address (IP address and port number).

I know what is bind and EJB (from example) to a name. Is this similar?

How to bind a local address to a server socket?

I am using:

providerSocket.bind(new InetSocketAddress("192.168.0.1", 0));

And I got Already Bound error!


Solution

A connection requires a client and a server.

For a client to send data to the server, the client must have the server's address and port number. Similarly, for the server to send data to the client, the server must have the client's address and port number.

Binding a socket means assigning an address and port number to the socket.

When you do:

providerSocket.bind(new InetSocketAddress("192.168.0.1", 0));

You get Already Bound error because providerSocket already has an address and port number, and assigning a new address / port number is not allowed. Once a ServerSocket is created, it is bound (unless it uses the parameterless constructor java.net.ServerSocket.ServerSocket()).



Answered By - Pacerier
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing