• Post Reply Bookmark Topic Watch Topic
  • New Topic

socket creation doubt ?  RSS feed

 
Anand Divakaran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I am trying to write a simple client server program, both the client and server program resides on the same local machine .
while creating a socket i dont know which port to mention
syntax
public Socket(InetAddress,int port)

How can i know which ports i can use .
i am working on my personal system so there is no question of admin problem
or restrictions
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use any port that's not currently in use. Most official services use ports below number 1024, so it's best to steer clear of those (and on UNIX, you can't use those without special privileges.) Pick a number above 2000 and if it works, then it's OK! Note that the important thing is that both client and server use the same number.
 
Anand Divakaran
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After creating a socket, can it be used to send and receive data .
or is it each time i use it for sending or receiving i have to close the socket and create a new one?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sockets can be used for two-way communication (sending and receiving), and they do not need to be closed every time they send or receive something.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



http://www.docdubya.com/belvedere/statement/browser.html

( ... an article written by Anish Shaikh ... )



[ Code here used by Nicholas Jordan in his project, thank you poster ! ]

[ Message edited 4:42 PM 9/21/2007: bias == (65535 - 46152) ]
[ September 23, 2007: Message edited by: Nicholas Jordan ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!