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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:05:28+00:00 2026-06-18T10:05:28+00:00

I am trying to bind the Socket on the client side to any particular

  • 0

I am trying to bind the Socket on the client side to any particular local port, in this code I used 20000.

Normal connections such as below works just fine. But does not allow for me to choose the local port.

hostSocket = new Socket(host,80);

So I tried this:

hostSocket = new Socket(host, 80, InetAddress.getLocalHost(), 20000);

and this:

hostSocket = new Socket();
hostSocket.bind(new InetSocketAddress("localhost", 20000));
hostSocket.connect(new InetSocketAddress(host,80));

But they both leave me with this exception… in the second case the exception occurred on the connect call. I’m not really sure what I am missing and I would love some pointers.

java.net.SocketException: Invalid argument or cannot assign requested address
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at com.mb.proxy.netflix.NetflixPrefetchingAgent.connect(NetflixPrefetchingAgent.java:98)
at com.mb.proxy.netflix.NetflixPrefetchingAgent.run(NetflixPrefetchingAgent.java:164)
at java.lang.Thread.run(Thread.java:679)
Exception in thread "Thread-19" java.lang.NullPointerException
at com.mb.proxy.netflix.NetflixPrefetchingAgent.prefetchChunk(NetflixPrefetchingAgent.java:272)
at com.mb.proxy.netflix.NetflixPrefetchingAgent.run(NetflixPrefetchingAgent.java:176)
at java.lang.Thread.run(Thread.java:679)
  • 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-18T10:05:29+00:00Added an answer on June 18, 2026 at 10:05 am

    You have to bind to the external (outbound) IP address of your machine, not localhost (127.0.0.1).

    The following works on my box without issue:

    Socket s = new Socket();
    s.bind(new InetSocketAddress("172.16.1.102", 5000));
    s.connect(new InetSocketAddress("google.com", 80));
    

    Where 172.16.1.102 is the NAT’d private network address assigned to this box via DHCP from my router.

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

Sidebar

Related Questions

I am trying to implement a socket server that listens to a particular port
I am trying to configure my TCP client to use a specific local port
I've recently gotten into trying to make server-client connections. I was able to make
in this code I'm trying to Listening to multi connection at the same time
I writing a server and a client and keep getting 'bind: Socket operation on
I am trying to make a timestamp server and client. The client code is:
Im trying to bind a list with datetime objects to my repeater. if (e.Item.ItemType
I'm trying to bind a list of data to a data grid, but can't
I am trying to bind a model coming from the server over json to
Hi I'm trying to bind data to a kendochart, but no bars are appearing

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.