Setting source port on a Java Socket?

后端 未结 5 1483
自闭症患者
自闭症患者 2021-02-20 09:03

I\'m very new to socket programming:

Is it possible to explicitly set the the source port on a Java Socket?

I am working on a client/server application in which

5条回答
  •  旧巷少年郎
    2021-02-20 10:01

    Yes, use the bind() method. This mirrors the bind() function available in most C-level socket implementations. Note that you can't always choose freely which port to use, on some system some ranges are reserved and considered off-limits to user applications.

提交回复
热议问题